@antipopp/agno-react 0.9.0 → 0.11.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 +18 -1
- package/dist/index.d.mts +124 -121
- package/dist/index.d.ts +124 -121
- package/dist/index.js +704 -534
- package/dist/index.mjs +711 -542
- package/package.json +13 -5
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
ComponentRegistry: () => ComponentRegistry,
|
|
35
35
|
GenerativeUIRenderer: () => GenerativeUIRenderer,
|
|
36
36
|
ToolHandlerProvider: () => ToolHandlerProvider,
|
|
37
|
+
clearCustomRenderRegistry: () => clearCustomRenderRegistry,
|
|
37
38
|
createAreaChart: () => createAreaChart,
|
|
38
39
|
createArtifact: () => createArtifact,
|
|
39
40
|
createBarChart: () => createBarChart,
|
|
@@ -63,60 +64,16 @@ __export(src_exports, {
|
|
|
63
64
|
});
|
|
64
65
|
module.exports = __toCommonJS(src_exports);
|
|
65
66
|
|
|
66
|
-
// src/context/AgnoContext.tsx
|
|
67
|
-
var import_react = require("react");
|
|
68
|
-
var import_agno_client = require("@antipopp/agno-client");
|
|
69
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
70
|
-
var AgnoContext = (0, import_react.createContext)(null);
|
|
71
|
-
function AgnoProvider({ config, children }) {
|
|
72
|
-
const client = (0, import_react.useMemo)(() => new import_agno_client.AgnoClient(config), []);
|
|
73
|
-
(0, import_react.useEffect)(() => {
|
|
74
|
-
client.updateConfig(config);
|
|
75
|
-
}, [client, config]);
|
|
76
|
-
(0, import_react.useEffect)(() => {
|
|
77
|
-
return () => {
|
|
78
|
-
client.removeAllListeners();
|
|
79
|
-
};
|
|
80
|
-
}, [client]);
|
|
81
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AgnoContext.Provider, { value: client, children });
|
|
82
|
-
}
|
|
83
|
-
function useAgnoClient() {
|
|
84
|
-
const client = (0, import_react.useContext)(AgnoContext);
|
|
85
|
-
if (!client) {
|
|
86
|
-
throw new Error("useAgnoClient must be used within an AgnoProvider");
|
|
87
|
-
}
|
|
88
|
-
return client;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// src/context/ToolHandlerContext.tsx
|
|
92
|
-
var import_react2 = require("react");
|
|
93
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
94
|
-
var ToolHandlerContext = (0, import_react2.createContext)(null);
|
|
95
|
-
function ToolHandlerProvider({ handlers: initialHandlers = {}, children }) {
|
|
96
|
-
const [handlers, setHandlers] = (0, import_react2.useState)(initialHandlers);
|
|
97
|
-
const registerHandler = (0, import_react2.useCallback)((name, handler) => {
|
|
98
|
-
setHandlers((prev) => ({ ...prev, [name]: handler }));
|
|
99
|
-
}, []);
|
|
100
|
-
const unregisterHandler = (0, import_react2.useCallback)((name) => {
|
|
101
|
-
setHandlers((prev) => {
|
|
102
|
-
const { [name]: _, ...rest } = prev;
|
|
103
|
-
return rest;
|
|
104
|
-
});
|
|
105
|
-
}, []);
|
|
106
|
-
const value = {
|
|
107
|
-
handlers,
|
|
108
|
-
registerHandler,
|
|
109
|
-
unregisterHandler
|
|
110
|
-
};
|
|
111
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ToolHandlerContext.Provider, { value, children });
|
|
112
|
-
}
|
|
113
|
-
function useToolHandlers() {
|
|
114
|
-
return (0, import_react2.useContext)(ToolHandlerContext);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
67
|
// src/components/GenerativeUIRenderer.tsx
|
|
118
68
|
var import_react4 = __toESM(require("react"));
|
|
119
69
|
|
|
70
|
+
// src/hooks/useAgnoToolExecution.ts
|
|
71
|
+
var import_react3 = require("react");
|
|
72
|
+
|
|
73
|
+
// src/context/AgnoContext.tsx
|
|
74
|
+
var import_agno_client = require("@antipopp/agno-client");
|
|
75
|
+
var import_react = require("react");
|
|
76
|
+
|
|
120
77
|
// src/utils/component-registry.ts
|
|
121
78
|
var ComponentRegistry = class _ComponentRegistry {
|
|
122
79
|
constructor() {
|
|
@@ -141,9 +98,9 @@ var ComponentRegistry = class _ComponentRegistry {
|
|
|
141
98
|
* Register multiple components at once
|
|
142
99
|
*/
|
|
143
100
|
registerBatch(components) {
|
|
144
|
-
|
|
101
|
+
for (const [type, renderer] of Object.entries(components)) {
|
|
145
102
|
this.register(type, renderer);
|
|
146
|
-
}
|
|
103
|
+
}
|
|
147
104
|
}
|
|
148
105
|
/**
|
|
149
106
|
* Get a registered component renderer
|
|
@@ -175,6 +132,17 @@ var ComponentRegistry = class _ComponentRegistry {
|
|
|
175
132
|
clear() {
|
|
176
133
|
this.components.clear();
|
|
177
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Reset the singleton instance.
|
|
137
|
+
* Call this during cleanup (e.g., when AgnoProvider unmounts) to prevent memory leaks.
|
|
138
|
+
* After calling this, getInstance() will create a fresh instance.
|
|
139
|
+
*/
|
|
140
|
+
static resetInstance() {
|
|
141
|
+
if (_ComponentRegistry.instance) {
|
|
142
|
+
_ComponentRegistry.instance.clear();
|
|
143
|
+
_ComponentRegistry.instance = void 0;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
178
146
|
};
|
|
179
147
|
function getComponentRegistry() {
|
|
180
148
|
return ComponentRegistry.getInstance();
|
|
@@ -186,39 +154,157 @@ function getChartComponent(name) {
|
|
|
186
154
|
return getComponentRegistry().get(`chart:${name}`);
|
|
187
155
|
}
|
|
188
156
|
|
|
157
|
+
// src/context/AgnoContext.tsx
|
|
158
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
159
|
+
var AgnoContext = (0, import_react.createContext)(null);
|
|
160
|
+
function AgnoProvider({ config, children }) {
|
|
161
|
+
const clientRef = (0, import_react.useRef)(null);
|
|
162
|
+
if (clientRef.current === null) {
|
|
163
|
+
clientRef.current = new import_agno_client.AgnoClient(config);
|
|
164
|
+
}
|
|
165
|
+
const client = clientRef.current;
|
|
166
|
+
(0, import_react.useEffect)(() => {
|
|
167
|
+
client.updateConfig(config);
|
|
168
|
+
}, [client, config]);
|
|
169
|
+
(0, import_react.useEffect)(() => {
|
|
170
|
+
return () => {
|
|
171
|
+
client.dispose();
|
|
172
|
+
clearCustomRenderRegistry();
|
|
173
|
+
ComponentRegistry.resetInstance();
|
|
174
|
+
};
|
|
175
|
+
}, [client]);
|
|
176
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AgnoContext.Provider, { value: client, children });
|
|
177
|
+
}
|
|
178
|
+
function useAgnoClient() {
|
|
179
|
+
const client = (0, import_react.useContext)(AgnoContext);
|
|
180
|
+
if (!client) {
|
|
181
|
+
throw new Error("useAgnoClient must be used within an AgnoProvider");
|
|
182
|
+
}
|
|
183
|
+
return client;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/context/ToolHandlerContext.tsx
|
|
187
|
+
var import_react2 = require("react");
|
|
188
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
189
|
+
var ToolHandlerContext = (0, import_react2.createContext)(null);
|
|
190
|
+
function ToolHandlerProvider({
|
|
191
|
+
handlers: initialHandlers = {},
|
|
192
|
+
children
|
|
193
|
+
}) {
|
|
194
|
+
const [handlers, setHandlers] = (0, import_react2.useState)(initialHandlers);
|
|
195
|
+
const registerHandler = (0, import_react2.useCallback)((name, handler) => {
|
|
196
|
+
setHandlers((prev) => ({ ...prev, [name]: handler }));
|
|
197
|
+
}, []);
|
|
198
|
+
const unregisterHandler = (0, import_react2.useCallback)((name) => {
|
|
199
|
+
setHandlers((prev) => {
|
|
200
|
+
const { [name]: _, ...rest } = prev;
|
|
201
|
+
return rest;
|
|
202
|
+
});
|
|
203
|
+
}, []);
|
|
204
|
+
const value = {
|
|
205
|
+
handlers,
|
|
206
|
+
registerHandler,
|
|
207
|
+
unregisterHandler
|
|
208
|
+
};
|
|
209
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ToolHandlerContext.Provider, { value, children });
|
|
210
|
+
}
|
|
211
|
+
function useToolHandlers() {
|
|
212
|
+
return (0, import_react2.useContext)(ToolHandlerContext);
|
|
213
|
+
}
|
|
214
|
+
|
|
189
215
|
// src/hooks/useAgnoToolExecution.ts
|
|
190
|
-
|
|
216
|
+
function isRecord(value) {
|
|
217
|
+
return typeof value === "object" && value !== null;
|
|
218
|
+
}
|
|
219
|
+
function getCustomRenderFunction(value) {
|
|
220
|
+
if (value.type !== "custom") {
|
|
221
|
+
return void 0;
|
|
222
|
+
}
|
|
223
|
+
const maybeRender = value.render;
|
|
224
|
+
return typeof maybeRender === "function" ? maybeRender : void 0;
|
|
225
|
+
}
|
|
191
226
|
var customRenderRegistry = /* @__PURE__ */ new Map();
|
|
192
227
|
function registerCustomRender(renderFn) {
|
|
193
228
|
const key = `custom-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
194
229
|
customRenderRegistry.set(key, renderFn);
|
|
195
230
|
return key;
|
|
196
231
|
}
|
|
232
|
+
function toSerializableUIComponent(spec) {
|
|
233
|
+
const renderFn = getCustomRenderFunction(spec);
|
|
234
|
+
if (!renderFn) {
|
|
235
|
+
return spec;
|
|
236
|
+
}
|
|
237
|
+
const { render: _render, ...uiWithoutRender } = spec;
|
|
238
|
+
return {
|
|
239
|
+
...uiWithoutRender,
|
|
240
|
+
renderKey: registerCustomRender(renderFn)
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
async function executeToolCall(tool, handlers) {
|
|
244
|
+
const handler = handlers[tool.tool_name];
|
|
245
|
+
if (!handler) {
|
|
246
|
+
return {
|
|
247
|
+
...tool,
|
|
248
|
+
result: JSON.stringify({
|
|
249
|
+
error: `No handler registered for ${tool.tool_name}`
|
|
250
|
+
})
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
try {
|
|
254
|
+
const result = await handler(tool.tool_args);
|
|
255
|
+
const { resultData, uiComponent } = processToolResult(result, tool);
|
|
256
|
+
return {
|
|
257
|
+
...tool,
|
|
258
|
+
result: resultData,
|
|
259
|
+
ui_component: uiComponent
|
|
260
|
+
};
|
|
261
|
+
} catch (error) {
|
|
262
|
+
return {
|
|
263
|
+
...tool,
|
|
264
|
+
result: JSON.stringify({
|
|
265
|
+
error: error instanceof Error ? error.message : String(error)
|
|
266
|
+
})
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async function hydrateToolUIForSession(tools, handlers, onHydrate) {
|
|
271
|
+
for (const tool of tools) {
|
|
272
|
+
if (tool.ui_component) {
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
const handler = handlers[tool.tool_name];
|
|
276
|
+
if (!handler) {
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
try {
|
|
280
|
+
const result = await handler(tool.tool_args);
|
|
281
|
+
const { uiComponent } = processToolResult(result, tool);
|
|
282
|
+
if (uiComponent) {
|
|
283
|
+
onHydrate(tool.tool_call_id, uiComponent);
|
|
284
|
+
}
|
|
285
|
+
} catch (error) {
|
|
286
|
+
console.error(`Failed to hydrate UI for ${tool.tool_name}:`, error);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
197
290
|
function getCustomRender(key) {
|
|
198
291
|
return customRenderRegistry.get(key);
|
|
199
292
|
}
|
|
293
|
+
function clearCustomRenderRegistry() {
|
|
294
|
+
customRenderRegistry.clear();
|
|
295
|
+
}
|
|
200
296
|
function isToolHandlerResult(value) {
|
|
201
|
-
return value &&
|
|
297
|
+
return isRecord(value) && ("data" in value || "ui" in value);
|
|
202
298
|
}
|
|
203
299
|
function isUIComponentSpec(value) {
|
|
204
|
-
return value && typeof value === "
|
|
300
|
+
return isRecord(value) && typeof value.type === "string";
|
|
205
301
|
}
|
|
206
302
|
function processToolResult(result, _tool) {
|
|
207
303
|
if (isToolHandlerResult(result)) {
|
|
208
304
|
const { data, ui } = result;
|
|
209
|
-
let uiComponent
|
|
305
|
+
let uiComponent;
|
|
210
306
|
if (ui) {
|
|
211
|
-
|
|
212
|
-
const renderKey = registerCustomRender(ui.render);
|
|
213
|
-
uiComponent = {
|
|
214
|
-
...ui,
|
|
215
|
-
renderKey,
|
|
216
|
-
render: void 0
|
|
217
|
-
// Don't store the function itself
|
|
218
|
-
};
|
|
219
|
-
} else {
|
|
220
|
-
uiComponent = ui;
|
|
221
|
-
}
|
|
307
|
+
uiComponent = toSerializableUIComponent(ui);
|
|
222
308
|
}
|
|
223
309
|
return {
|
|
224
310
|
resultData: typeof data === "string" ? data : JSON.stringify(data),
|
|
@@ -226,17 +312,7 @@ function processToolResult(result, _tool) {
|
|
|
226
312
|
};
|
|
227
313
|
}
|
|
228
314
|
if (isUIComponentSpec(result)) {
|
|
229
|
-
|
|
230
|
-
if (result.type === "custom" && typeof result.render === "function") {
|
|
231
|
-
const renderKey = registerCustomRender(result.render);
|
|
232
|
-
uiComponent = {
|
|
233
|
-
...result,
|
|
234
|
-
renderKey,
|
|
235
|
-
render: void 0
|
|
236
|
-
};
|
|
237
|
-
} else {
|
|
238
|
-
uiComponent = result;
|
|
239
|
-
}
|
|
315
|
+
const uiComponent = toSerializableUIComponent(result);
|
|
240
316
|
return {
|
|
241
317
|
resultData: JSON.stringify(result),
|
|
242
318
|
uiComponent
|
|
@@ -297,35 +373,9 @@ function useAgnoToolExecution(handlers = {}, autoExecute = true) {
|
|
|
297
373
|
setExecutionError(void 0);
|
|
298
374
|
try {
|
|
299
375
|
const updatedTools = await Promise.all(
|
|
300
|
-
pendingTools.map(
|
|
301
|
-
const handler = mergedHandlers[tool.tool_name];
|
|
302
|
-
if (!handler) {
|
|
303
|
-
return {
|
|
304
|
-
...tool,
|
|
305
|
-
result: JSON.stringify({
|
|
306
|
-
error: `No handler registered for ${tool.tool_name}`
|
|
307
|
-
})
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
try {
|
|
311
|
-
const result = await handler(tool.tool_args);
|
|
312
|
-
const { resultData, uiComponent } = processToolResult(result, tool);
|
|
313
|
-
return {
|
|
314
|
-
...tool,
|
|
315
|
-
result: resultData,
|
|
316
|
-
ui_component: uiComponent
|
|
317
|
-
};
|
|
318
|
-
} catch (error) {
|
|
319
|
-
return {
|
|
320
|
-
...tool,
|
|
321
|
-
result: JSON.stringify({
|
|
322
|
-
error: error instanceof Error ? error.message : String(error)
|
|
323
|
-
})
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
})
|
|
376
|
+
pendingTools.map((tool) => executeToolCall(tool, mergedHandlers))
|
|
327
377
|
);
|
|
328
|
-
const toolsWithUI = updatedTools.filter((
|
|
378
|
+
const toolsWithUI = updatedTools.filter((tool) => tool.ui_component);
|
|
329
379
|
if (toolsWithUI.length > 0) {
|
|
330
380
|
client.emit("ui:render", {
|
|
331
381
|
tools: updatedTools,
|
|
@@ -342,28 +392,20 @@ function useAgnoToolExecution(handlers = {}, autoExecute = true) {
|
|
|
342
392
|
}
|
|
343
393
|
}, [client, mergedHandlers, isPaused, pendingTools]);
|
|
344
394
|
(0, import_react3.useEffect)(() => {
|
|
345
|
-
const handleSessionLoaded =
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
continue;
|
|
353
|
-
const handler = mergedHandlers[tool.tool_name];
|
|
354
|
-
if (!handler)
|
|
355
|
-
continue;
|
|
356
|
-
try {
|
|
357
|
-
const result = await handler(tool.tool_args);
|
|
358
|
-
const { uiComponent } = processToolResult(result, tool);
|
|
359
|
-
if (uiComponent) {
|
|
360
|
-
client.hydrateToolCallUI(tool.tool_call_id, uiComponent);
|
|
361
|
-
}
|
|
362
|
-
} catch (err) {
|
|
363
|
-
console.error(`Failed to hydrate UI for ${tool.tool_name}:`, err);
|
|
364
|
-
}
|
|
395
|
+
const handleSessionLoaded = (_sessionId) => {
|
|
396
|
+
const tools = client.getMessages().flatMap((message) => message.tool_calls || []);
|
|
397
|
+
hydrateToolUIForSession(
|
|
398
|
+
tools,
|
|
399
|
+
mergedHandlers,
|
|
400
|
+
(toolCallId, uiComponent) => {
|
|
401
|
+
client.hydrateToolCallUI(toolCallId, uiComponent);
|
|
365
402
|
}
|
|
366
|
-
|
|
403
|
+
).catch((error) => {
|
|
404
|
+
console.error(
|
|
405
|
+
"[useAgnoToolExecution] Failed to hydrate session UI:",
|
|
406
|
+
error
|
|
407
|
+
);
|
|
408
|
+
});
|
|
367
409
|
};
|
|
368
410
|
client.on("session:loaded", handleSessionLoaded);
|
|
369
411
|
return () => {
|
|
@@ -371,29 +413,9 @@ function useAgnoToolExecution(handlers = {}, autoExecute = true) {
|
|
|
371
413
|
};
|
|
372
414
|
}, [client, mergedHandlers]);
|
|
373
415
|
const executeTools = (0, import_react3.useCallback)(
|
|
374
|
-
|
|
416
|
+
(tools) => {
|
|
375
417
|
return Promise.all(
|
|
376
|
-
tools.map(
|
|
377
|
-
const handler = mergedHandlers[tool.tool_name];
|
|
378
|
-
if (!handler)
|
|
379
|
-
return tool;
|
|
380
|
-
try {
|
|
381
|
-
const result = await handler(tool.tool_args);
|
|
382
|
-
const { resultData, uiComponent } = processToolResult(result, tool);
|
|
383
|
-
return {
|
|
384
|
-
...tool,
|
|
385
|
-
result: resultData,
|
|
386
|
-
ui_component: uiComponent
|
|
387
|
-
};
|
|
388
|
-
} catch (error) {
|
|
389
|
-
return {
|
|
390
|
-
...tool,
|
|
391
|
-
result: JSON.stringify({
|
|
392
|
-
error: error instanceof Error ? error.message : String(error)
|
|
393
|
-
})
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
})
|
|
418
|
+
tools.map((tool) => executeToolCall(tool, mergedHandlers))
|
|
397
419
|
);
|
|
398
420
|
},
|
|
399
421
|
[mergedHandlers]
|
|
@@ -414,10 +436,18 @@ function useAgnoToolExecution(handlers = {}, autoExecute = true) {
|
|
|
414
436
|
[client, isPaused]
|
|
415
437
|
);
|
|
416
438
|
(0, import_react3.useEffect)(() => {
|
|
417
|
-
if (autoExecute && isPaused && !isExecuting && pendingTools.length > 0) {
|
|
418
|
-
executeAndContinue()
|
|
439
|
+
if (autoExecute && isPaused && !isExecuting && !executionError && pendingTools.length > 0) {
|
|
440
|
+
executeAndContinue().catch(() => {
|
|
441
|
+
});
|
|
419
442
|
}
|
|
420
|
-
}, [
|
|
443
|
+
}, [
|
|
444
|
+
autoExecute,
|
|
445
|
+
isPaused,
|
|
446
|
+
isExecuting,
|
|
447
|
+
executionError,
|
|
448
|
+
pendingTools.length,
|
|
449
|
+
executeAndContinue
|
|
450
|
+
]);
|
|
421
451
|
return {
|
|
422
452
|
/** Whether the run is currently paused awaiting tool execution */
|
|
423
453
|
isPaused,
|
|
@@ -447,183 +477,532 @@ var UIErrorBoundary = class extends import_react4.default.Component {
|
|
|
447
477
|
return { hasError: true, error };
|
|
448
478
|
}
|
|
449
479
|
componentDidCatch(error, errorInfo) {
|
|
450
|
-
console.error(
|
|
480
|
+
console.error(
|
|
481
|
+
"[GenerativeUIRenderer] Error rendering component:",
|
|
482
|
+
error,
|
|
483
|
+
errorInfo
|
|
484
|
+
);
|
|
451
485
|
this.props.onError?.(error);
|
|
452
486
|
}
|
|
453
487
|
render() {
|
|
454
488
|
if (this.state.hasError) {
|
|
455
|
-
return this.props.fallback || /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "
|
|
489
|
+
return this.props.fallback || /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "rounded-md border border-red-300 bg-red-50 p-4 text-red-800", children: [
|
|
456
490
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "font-semibold", children: "Failed to render UI component" }),
|
|
457
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-sm
|
|
491
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "mt-1 text-sm", children: this.state.error?.message || "Unknown error" })
|
|
458
492
|
] });
|
|
459
493
|
}
|
|
460
494
|
return this.props.children;
|
|
461
495
|
}
|
|
462
496
|
};
|
|
463
|
-
function
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
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: [
|
|
478
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "font-semibold", children: "Custom component not available" }),
|
|
479
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-sm mt-1", children: "The custom render function for this component is not available." })
|
|
480
|
-
] });
|
|
497
|
+
function joinClassNames(...classNames) {
|
|
498
|
+
return classNames.filter(Boolean).join(" ");
|
|
499
|
+
}
|
|
500
|
+
function renderHeader(title, description) {
|
|
501
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
502
|
+
title ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "mb-2 font-semibold", children: title }) : null,
|
|
503
|
+
description ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "mb-4 text-gray-600 text-sm", children: description }) : null
|
|
504
|
+
] });
|
|
505
|
+
}
|
|
506
|
+
function renderFromRegistry(renderer, props) {
|
|
507
|
+
if (!renderer) {
|
|
508
|
+
return void 0;
|
|
481
509
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
return
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
510
|
+
return renderer(props);
|
|
511
|
+
}
|
|
512
|
+
function getSpecKey(spec) {
|
|
513
|
+
switch (spec.type) {
|
|
514
|
+
case "chart":
|
|
515
|
+
return `${spec.type}-${spec.component}-${spec.title ?? "untitled"}-${spec.props.data.length}`;
|
|
516
|
+
case "card-grid":
|
|
517
|
+
return `${spec.type}-${spec.title ?? "untitled"}-${spec.props.cards.map((card) => card.id).join("|")}`;
|
|
518
|
+
case "table":
|
|
519
|
+
return `${spec.type}-${spec.title ?? "untitled"}-${spec.props.columns.map((column) => column.key).join("|")}`;
|
|
520
|
+
case "markdown":
|
|
521
|
+
return `${spec.type}-${spec.props.content.slice(0, 48)}`;
|
|
522
|
+
case "custom":
|
|
523
|
+
return `${spec.type}-${spec.renderKey}`;
|
|
524
|
+
case "artifact":
|
|
525
|
+
return `${spec.type}-${spec.title ?? "untitled"}-${spec.props.content.length}`;
|
|
526
|
+
default:
|
|
527
|
+
return "unknown-spec";
|
|
498
528
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
cardGridSpec.description && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-sm text-gray-600 mb-4", children: cardGridSpec.description }),
|
|
506
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CardGridRenderer, { ...cardGridSpec.props })
|
|
507
|
-
] }) });
|
|
508
|
-
}
|
|
529
|
+
}
|
|
530
|
+
function renderCustomSpec(spec, className, onError) {
|
|
531
|
+
const renderFn = getCustomRender(spec.renderKey);
|
|
532
|
+
if (renderFn) {
|
|
533
|
+
const renderedContent = renderFn(spec.props || {});
|
|
534
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UIErrorBoundary, { onError, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className, children: renderedContent }) });
|
|
509
535
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
536
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
537
|
+
"div",
|
|
538
|
+
{
|
|
539
|
+
className: joinClassNames(
|
|
540
|
+
"rounded-md border border-yellow-300 bg-yellow-50 p-4 text-yellow-800",
|
|
541
|
+
className
|
|
542
|
+
),
|
|
543
|
+
children: [
|
|
544
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "font-semibold", children: "Custom component not available" }),
|
|
545
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "mt-1 text-sm", children: "The custom render function for this component is not available." })
|
|
546
|
+
]
|
|
519
547
|
}
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
function renderChartSpec(spec, className, onError) {
|
|
551
|
+
const registry = getComponentRegistry();
|
|
552
|
+
const chartType = `chart:${spec.component}`;
|
|
553
|
+
const chartRenderer = registry.get(chartType);
|
|
554
|
+
const renderedChart = renderFromRegistry(
|
|
555
|
+
chartRenderer,
|
|
556
|
+
spec.props
|
|
557
|
+
);
|
|
558
|
+
if (renderedChart) {
|
|
559
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UIErrorBoundary, { onError, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className, children: [
|
|
560
|
+
renderHeader(spec.title, spec.description),
|
|
561
|
+
renderedChart
|
|
562
|
+
] }) });
|
|
520
563
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
564
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
565
|
+
"div",
|
|
566
|
+
{
|
|
567
|
+
className: joinClassNames(
|
|
568
|
+
"rounded-md border border-gray-300 p-4",
|
|
569
|
+
className
|
|
570
|
+
),
|
|
571
|
+
children: [
|
|
572
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "mb-2 font-semibold", children: spec.title || "Chart Data" }),
|
|
573
|
+
spec.description ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "mb-2 text-gray-600 text-sm", children: spec.description }) : null,
|
|
574
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { className: "overflow-auto rounded bg-gray-100 p-2 text-xs", children: JSON.stringify(spec.props.data, null, 2) })
|
|
575
|
+
]
|
|
526
576
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
function renderCardGridSpec(spec, className, onError) {
|
|
580
|
+
const registry = getComponentRegistry();
|
|
581
|
+
const cardGridRenderer = registry.get("card-grid");
|
|
582
|
+
const renderedGrid = renderFromRegistry(
|
|
583
|
+
cardGridRenderer,
|
|
584
|
+
spec.props
|
|
585
|
+
);
|
|
586
|
+
if (!renderedGrid) {
|
|
587
|
+
return renderUnsupportedSpec(spec, className);
|
|
536
588
|
}
|
|
537
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
spec.type
|
|
542
|
-
] })
|
|
543
|
-
] });
|
|
589
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UIErrorBoundary, { onError, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className, children: [
|
|
590
|
+
renderHeader(spec.title, spec.description),
|
|
591
|
+
renderedGrid
|
|
592
|
+
] }) });
|
|
544
593
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
label: bar.label || bar.key,
|
|
560
|
-
color: bar.color
|
|
561
|
-
})),
|
|
562
|
-
showLegend: options?.showLegend ?? true,
|
|
563
|
-
showGrid: options?.showGrid ?? true,
|
|
564
|
-
height: options?.height,
|
|
565
|
-
width: options?.width
|
|
566
|
-
}
|
|
567
|
-
};
|
|
594
|
+
function renderTableSpec(spec, className, onError) {
|
|
595
|
+
const registry = getComponentRegistry();
|
|
596
|
+
const tableRenderer = registry.get("table");
|
|
597
|
+
const renderedTable = renderFromRegistry(
|
|
598
|
+
tableRenderer,
|
|
599
|
+
spec.props
|
|
600
|
+
);
|
|
601
|
+
if (!renderedTable) {
|
|
602
|
+
return renderUnsupportedSpec(spec, className);
|
|
603
|
+
}
|
|
604
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UIErrorBoundary, { onError, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className, children: [
|
|
605
|
+
renderHeader(spec.title, spec.description),
|
|
606
|
+
renderedTable
|
|
607
|
+
] }) });
|
|
568
608
|
}
|
|
569
|
-
function
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
key: line.key,
|
|
581
|
-
label: line.label || line.key,
|
|
582
|
-
color: line.color
|
|
583
|
-
})),
|
|
584
|
-
showLegend: options?.showLegend ?? true,
|
|
585
|
-
showGrid: options?.showGrid ?? true,
|
|
586
|
-
height: options?.height,
|
|
587
|
-
width: options?.width
|
|
588
|
-
}
|
|
589
|
-
};
|
|
609
|
+
function renderMarkdownSpec(spec, className, onError) {
|
|
610
|
+
const registry = getComponentRegistry();
|
|
611
|
+
const markdownRenderer = registry.get("markdown");
|
|
612
|
+
const renderedMarkdown = renderFromRegistry(
|
|
613
|
+
markdownRenderer,
|
|
614
|
+
spec.props
|
|
615
|
+
);
|
|
616
|
+
if (!renderedMarkdown) {
|
|
617
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className, children: spec.props.content });
|
|
618
|
+
}
|
|
619
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UIErrorBoundary, { onError, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className, children: renderedMarkdown }) });
|
|
590
620
|
}
|
|
591
|
-
function
|
|
592
|
-
return {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
pie: {
|
|
601
|
-
dataKey,
|
|
602
|
-
nameKey,
|
|
603
|
-
label: options?.showLabel ?? true
|
|
621
|
+
function renderArtifactSpec(spec, className, onError) {
|
|
622
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UIErrorBoundary, { onError, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: joinClassNames("rounded-md border p-4", className), children: [
|
|
623
|
+
spec.title ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "mb-4 font-semibold", children: spec.title }) : null,
|
|
624
|
+
spec.description ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "mb-4 text-gray-600 text-sm", children: spec.description }) : null,
|
|
625
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "space-y-4", children: spec.props.content.map((childSpec) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
626
|
+
GenerativeUIRenderer,
|
|
627
|
+
{
|
|
628
|
+
onError,
|
|
629
|
+
spec: childSpec
|
|
604
630
|
},
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
631
|
+
getSpecKey(childSpec)
|
|
632
|
+
)) })
|
|
633
|
+
] }) });
|
|
634
|
+
}
|
|
635
|
+
function renderUnsupportedSpec(spec, className) {
|
|
636
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
637
|
+
"div",
|
|
638
|
+
{
|
|
639
|
+
className: joinClassNames(
|
|
640
|
+
"rounded-md border border-gray-300 p-4",
|
|
641
|
+
className
|
|
642
|
+
),
|
|
643
|
+
children: [
|
|
644
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "font-semibold", children: "Unsupported UI component" }),
|
|
645
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { className: "mt-1 text-gray-600 text-sm", children: [
|
|
646
|
+
"Component type: ",
|
|
647
|
+
spec.type
|
|
648
|
+
] })
|
|
649
|
+
]
|
|
608
650
|
}
|
|
609
|
-
|
|
651
|
+
);
|
|
610
652
|
}
|
|
611
|
-
function
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
653
|
+
function GenerativeUIRenderer({
|
|
654
|
+
spec,
|
|
655
|
+
className,
|
|
656
|
+
onError
|
|
657
|
+
}) {
|
|
658
|
+
switch (spec.type) {
|
|
659
|
+
case "custom":
|
|
660
|
+
return renderCustomSpec(spec, className, onError);
|
|
661
|
+
case "chart":
|
|
662
|
+
return renderChartSpec(spec, className, onError);
|
|
663
|
+
case "card-grid":
|
|
664
|
+
return renderCardGridSpec(spec, className, onError);
|
|
665
|
+
case "table":
|
|
666
|
+
return renderTableSpec(spec, className, onError);
|
|
667
|
+
case "markdown":
|
|
668
|
+
return renderMarkdownSpec(spec, className, onError);
|
|
669
|
+
case "artifact":
|
|
670
|
+
return renderArtifactSpec(spec, className, onError);
|
|
671
|
+
default:
|
|
672
|
+
return renderUnsupportedSpec(spec, className);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// src/hooks/useAgnoActions.ts
|
|
677
|
+
var import_react5 = require("react");
|
|
678
|
+
function useAgnoActions() {
|
|
679
|
+
const client = useAgnoClient();
|
|
680
|
+
const [isInitializing, setIsInitializing] = (0, import_react5.useState)(false);
|
|
681
|
+
const [error, setError] = (0, import_react5.useState)();
|
|
682
|
+
const initialize = (0, import_react5.useCallback)(
|
|
683
|
+
async (options) => {
|
|
684
|
+
setIsInitializing(true);
|
|
685
|
+
setError(void 0);
|
|
686
|
+
try {
|
|
687
|
+
const result = await client.initialize(options);
|
|
688
|
+
return result;
|
|
689
|
+
} catch (err) {
|
|
690
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
691
|
+
setError(errorMessage);
|
|
692
|
+
throw err;
|
|
693
|
+
} finally {
|
|
694
|
+
setIsInitializing(false);
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
[client]
|
|
698
|
+
);
|
|
699
|
+
const checkStatus = (0, import_react5.useCallback)(
|
|
700
|
+
async (options) => {
|
|
701
|
+
setError(void 0);
|
|
702
|
+
try {
|
|
703
|
+
return await client.checkStatus(options);
|
|
704
|
+
} catch (err) {
|
|
705
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
706
|
+
setError(errorMessage);
|
|
707
|
+
return false;
|
|
708
|
+
}
|
|
709
|
+
},
|
|
710
|
+
[client]
|
|
711
|
+
);
|
|
712
|
+
const fetchAgents = (0, import_react5.useCallback)(
|
|
713
|
+
async (options) => {
|
|
714
|
+
setError(void 0);
|
|
715
|
+
try {
|
|
716
|
+
return await client.fetchAgents(options);
|
|
717
|
+
} catch (err) {
|
|
718
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
719
|
+
setError(errorMessage);
|
|
720
|
+
throw err;
|
|
721
|
+
}
|
|
722
|
+
},
|
|
723
|
+
[client]
|
|
724
|
+
);
|
|
725
|
+
const fetchTeams = (0, import_react5.useCallback)(
|
|
726
|
+
async (options) => {
|
|
727
|
+
setError(void 0);
|
|
728
|
+
try {
|
|
729
|
+
return await client.fetchTeams(options);
|
|
730
|
+
} catch (err) {
|
|
731
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
732
|
+
setError(errorMessage);
|
|
733
|
+
throw err;
|
|
734
|
+
}
|
|
735
|
+
},
|
|
736
|
+
[client]
|
|
737
|
+
);
|
|
738
|
+
const updateConfig = (0, import_react5.useCallback)(
|
|
739
|
+
(updates) => {
|
|
740
|
+
client.updateConfig(updates);
|
|
741
|
+
},
|
|
742
|
+
[client]
|
|
743
|
+
);
|
|
744
|
+
return {
|
|
745
|
+
initialize,
|
|
746
|
+
checkStatus,
|
|
747
|
+
fetchAgents,
|
|
748
|
+
fetchTeams,
|
|
749
|
+
updateConfig,
|
|
750
|
+
isInitializing,
|
|
751
|
+
error
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
// src/hooks/useAgnoChat.ts
|
|
756
|
+
var import_react6 = require("react");
|
|
757
|
+
function useAgnoChat() {
|
|
758
|
+
const client = useAgnoClient();
|
|
759
|
+
const [messages, setMessages] = (0, import_react6.useState)(client.getMessages());
|
|
760
|
+
const [state, setState] = (0, import_react6.useState)(client.getState());
|
|
761
|
+
const [error, setError] = (0, import_react6.useState)();
|
|
762
|
+
(0, import_react6.useEffect)(() => {
|
|
763
|
+
const handleMessageUpdate = (updatedMessages) => {
|
|
764
|
+
setMessages(updatedMessages);
|
|
765
|
+
};
|
|
766
|
+
const handleMessageComplete = (updatedMessages) => {
|
|
767
|
+
setMessages(updatedMessages);
|
|
768
|
+
};
|
|
769
|
+
const handleMessageRefreshed = (updatedMessages) => {
|
|
770
|
+
setMessages(updatedMessages);
|
|
771
|
+
};
|
|
772
|
+
const handleMessageError = (errorMessage) => {
|
|
773
|
+
setError(errorMessage);
|
|
774
|
+
};
|
|
775
|
+
const handleStateChange = (newState) => {
|
|
776
|
+
setState(newState);
|
|
777
|
+
};
|
|
778
|
+
const handleUIRender = (event) => {
|
|
779
|
+
const { tools } = event;
|
|
780
|
+
for (const tool of tools) {
|
|
781
|
+
if (tool.ui_component) {
|
|
782
|
+
client.hydrateToolCallUI(tool.tool_call_id, tool.ui_component);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
client.on("message:update", handleMessageUpdate);
|
|
787
|
+
client.on("message:complete", handleMessageComplete);
|
|
788
|
+
client.on("message:refreshed", handleMessageRefreshed);
|
|
789
|
+
client.on("message:error", handleMessageError);
|
|
790
|
+
client.on("state:change", handleStateChange);
|
|
791
|
+
client.on("ui:render", handleUIRender);
|
|
792
|
+
setMessages(client.getMessages());
|
|
793
|
+
setState(client.getState());
|
|
794
|
+
return () => {
|
|
795
|
+
client.off("message:update", handleMessageUpdate);
|
|
796
|
+
client.off("message:complete", handleMessageComplete);
|
|
797
|
+
client.off("message:refreshed", handleMessageRefreshed);
|
|
798
|
+
client.off("message:error", handleMessageError);
|
|
799
|
+
client.off("state:change", handleStateChange);
|
|
800
|
+
client.off("ui:render", handleUIRender);
|
|
801
|
+
};
|
|
802
|
+
}, [client]);
|
|
803
|
+
const sendMessage = (0, import_react6.useCallback)(
|
|
804
|
+
async (message, options) => {
|
|
805
|
+
setError(void 0);
|
|
806
|
+
try {
|
|
807
|
+
await client.sendMessage(message, options);
|
|
808
|
+
} catch (err) {
|
|
809
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
810
|
+
setError(errorMessage);
|
|
811
|
+
throw err;
|
|
812
|
+
}
|
|
813
|
+
},
|
|
814
|
+
[client]
|
|
815
|
+
);
|
|
816
|
+
const cancelRun = (0, import_react6.useCallback)(async () => {
|
|
817
|
+
try {
|
|
818
|
+
await client.cancelRun();
|
|
819
|
+
} catch (err) {
|
|
820
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
821
|
+
setError(errorMessage);
|
|
822
|
+
throw err;
|
|
823
|
+
}
|
|
824
|
+
}, [client]);
|
|
825
|
+
const clearMessages = (0, import_react6.useCallback)(() => {
|
|
826
|
+
client.clearMessages();
|
|
827
|
+
setMessages([]);
|
|
828
|
+
setError(void 0);
|
|
829
|
+
}, [client]);
|
|
830
|
+
return {
|
|
831
|
+
messages,
|
|
832
|
+
sendMessage,
|
|
833
|
+
clearMessages,
|
|
834
|
+
cancelRun,
|
|
835
|
+
isStreaming: state.isStreaming,
|
|
836
|
+
isRefreshing: state.isRefreshing,
|
|
837
|
+
isPaused: state.isPaused,
|
|
838
|
+
isCancelling: state.isCancelling,
|
|
839
|
+
currentRunId: state.currentRunId,
|
|
840
|
+
error,
|
|
841
|
+
state
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
// src/hooks/useAgnoSession.ts
|
|
846
|
+
var import_react7 = require("react");
|
|
847
|
+
function useAgnoSession() {
|
|
848
|
+
const client = useAgnoClient();
|
|
849
|
+
const [sessions, setSessions] = (0, import_react7.useState)([]);
|
|
850
|
+
const [currentSessionId, setCurrentSessionId] = (0, import_react7.useState)(
|
|
851
|
+
client.getConfig().sessionId
|
|
852
|
+
);
|
|
853
|
+
const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
|
|
854
|
+
const [error, setError] = (0, import_react7.useState)();
|
|
855
|
+
(0, import_react7.useEffect)(() => {
|
|
856
|
+
const handleSessionLoaded = (sessionId) => {
|
|
857
|
+
setCurrentSessionId(sessionId);
|
|
858
|
+
};
|
|
859
|
+
const handleSessionCreated = (session) => {
|
|
860
|
+
setSessions((prev) => [session, ...prev]);
|
|
861
|
+
setCurrentSessionId(session.session_id);
|
|
862
|
+
};
|
|
863
|
+
const handleStateChange = () => {
|
|
864
|
+
const config = client.getConfig();
|
|
865
|
+
setCurrentSessionId(config.sessionId);
|
|
866
|
+
setSessions(client.getState().sessions);
|
|
867
|
+
};
|
|
868
|
+
client.on("session:loaded", handleSessionLoaded);
|
|
869
|
+
client.on("session:created", handleSessionCreated);
|
|
870
|
+
client.on("state:change", handleStateChange);
|
|
871
|
+
setSessions(client.getState().sessions);
|
|
872
|
+
setCurrentSessionId(client.getConfig().sessionId);
|
|
873
|
+
return () => {
|
|
874
|
+
client.off("session:loaded", handleSessionLoaded);
|
|
875
|
+
client.off("session:created", handleSessionCreated);
|
|
876
|
+
client.off("state:change", handleStateChange);
|
|
877
|
+
};
|
|
878
|
+
}, [client]);
|
|
879
|
+
const loadSession = (0, import_react7.useCallback)(
|
|
880
|
+
async (sessionId, options) => {
|
|
881
|
+
setIsLoading(true);
|
|
882
|
+
setError(void 0);
|
|
883
|
+
try {
|
|
884
|
+
const messages = await client.loadSession(sessionId, options);
|
|
885
|
+
setCurrentSessionId(sessionId);
|
|
886
|
+
return messages;
|
|
887
|
+
} catch (err) {
|
|
888
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
889
|
+
setError(errorMessage);
|
|
890
|
+
throw err;
|
|
891
|
+
} finally {
|
|
892
|
+
setIsLoading(false);
|
|
893
|
+
}
|
|
894
|
+
},
|
|
895
|
+
[client]
|
|
896
|
+
);
|
|
897
|
+
const fetchSessions = (0, import_react7.useCallback)(
|
|
898
|
+
async (options) => {
|
|
899
|
+
setIsLoading(true);
|
|
900
|
+
setError(void 0);
|
|
901
|
+
try {
|
|
902
|
+
const fetchedSessions = await client.fetchSessions(options);
|
|
903
|
+
setSessions(fetchedSessions);
|
|
904
|
+
return fetchedSessions;
|
|
905
|
+
} catch (err) {
|
|
906
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
907
|
+
setError(errorMessage);
|
|
908
|
+
throw err;
|
|
909
|
+
} finally {
|
|
910
|
+
setIsLoading(false);
|
|
911
|
+
}
|
|
912
|
+
},
|
|
913
|
+
[client]
|
|
914
|
+
);
|
|
915
|
+
return {
|
|
916
|
+
sessions,
|
|
917
|
+
currentSessionId,
|
|
918
|
+
loadSession,
|
|
919
|
+
fetchSessions,
|
|
920
|
+
isLoading,
|
|
921
|
+
error
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
// src/utils/ui-helpers.ts
|
|
926
|
+
function createBarChart(data, xKey, bars, options) {
|
|
927
|
+
return {
|
|
928
|
+
type: "chart",
|
|
929
|
+
component: "BarChart",
|
|
930
|
+
layout: options?.layout,
|
|
931
|
+
title: options?.title,
|
|
932
|
+
description: options?.description,
|
|
933
|
+
props: {
|
|
934
|
+
data,
|
|
935
|
+
xKey,
|
|
936
|
+
bars: bars.map((bar) => ({
|
|
937
|
+
key: bar.key,
|
|
938
|
+
label: bar.label || bar.key,
|
|
939
|
+
color: bar.color
|
|
940
|
+
})),
|
|
941
|
+
showLegend: options?.showLegend ?? true,
|
|
942
|
+
showGrid: options?.showGrid ?? true,
|
|
943
|
+
height: options?.height,
|
|
944
|
+
width: options?.width
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
function createLineChart(data, xKey, lines, options) {
|
|
949
|
+
return {
|
|
950
|
+
type: "chart",
|
|
951
|
+
component: "LineChart",
|
|
952
|
+
layout: options?.layout,
|
|
953
|
+
title: options?.title,
|
|
954
|
+
description: options?.description,
|
|
955
|
+
props: {
|
|
956
|
+
data,
|
|
957
|
+
xKey,
|
|
958
|
+
lines: lines.map((line) => ({
|
|
959
|
+
key: line.key,
|
|
960
|
+
label: line.label || line.key,
|
|
961
|
+
color: line.color
|
|
962
|
+
})),
|
|
963
|
+
showLegend: options?.showLegend ?? true,
|
|
964
|
+
showGrid: options?.showGrid ?? true,
|
|
965
|
+
height: options?.height,
|
|
966
|
+
width: options?.width
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
function createPieChart(data, dataKey, nameKey, options) {
|
|
971
|
+
return {
|
|
972
|
+
type: "chart",
|
|
973
|
+
component: "PieChart",
|
|
974
|
+
layout: options?.layout,
|
|
975
|
+
title: options?.title,
|
|
976
|
+
description: options?.description,
|
|
977
|
+
props: {
|
|
978
|
+
data,
|
|
979
|
+
pie: {
|
|
980
|
+
dataKey,
|
|
981
|
+
nameKey,
|
|
982
|
+
label: options?.showLabel ?? true
|
|
983
|
+
},
|
|
984
|
+
showLegend: options?.showLegend ?? true,
|
|
985
|
+
height: options?.height || 400,
|
|
986
|
+
width: options?.width
|
|
987
|
+
}
|
|
988
|
+
};
|
|
989
|
+
}
|
|
990
|
+
function createAreaChart(data, xKey, areas, options) {
|
|
991
|
+
return {
|
|
992
|
+
type: "chart",
|
|
993
|
+
component: "AreaChart",
|
|
994
|
+
layout: options?.layout,
|
|
995
|
+
title: options?.title,
|
|
996
|
+
description: options?.description,
|
|
997
|
+
props: {
|
|
998
|
+
data,
|
|
999
|
+
xKey,
|
|
1000
|
+
areas: areas.map((area) => ({
|
|
1001
|
+
key: area.key,
|
|
1002
|
+
label: area.label || area.key,
|
|
1003
|
+
color: area.color
|
|
1004
|
+
})),
|
|
1005
|
+
showLegend: options?.showLegend ?? true,
|
|
627
1006
|
showGrid: options?.showGrid ?? true,
|
|
628
1007
|
height: options?.height,
|
|
629
1008
|
width: options?.width
|
|
@@ -709,10 +1088,15 @@ function createSmartChart(data, options) {
|
|
|
709
1088
|
const firstItem = data[0];
|
|
710
1089
|
const keys = Object.keys(firstItem);
|
|
711
1090
|
const xKey = options?.xKey || keys.find(
|
|
712
|
-
(k) => ["name", "label", "category", "date", "time", "month", "year"].includes(
|
|
1091
|
+
(k) => ["name", "label", "category", "date", "time", "month", "year"].includes(
|
|
1092
|
+
k.toLowerCase()
|
|
1093
|
+
)
|
|
713
1094
|
) || keys[0];
|
|
714
|
-
const numericKeys = keys.filter(
|
|
1095
|
+
const numericKeys = keys.filter(
|
|
1096
|
+
(k) => k !== xKey && typeof firstItem[k] === "number"
|
|
1097
|
+
);
|
|
715
1098
|
const yKeys = options?.yKeys || numericKeys;
|
|
1099
|
+
const firstValueKey = yKeys[0] ?? numericKeys[0];
|
|
716
1100
|
if (options?.preferredType) {
|
|
717
1101
|
switch (options.preferredType) {
|
|
718
1102
|
case "bar":
|
|
@@ -737,11 +1121,18 @@ function createSmartChart(data, options) {
|
|
|
737
1121
|
options
|
|
738
1122
|
);
|
|
739
1123
|
case "pie":
|
|
740
|
-
return createPieChart(data,
|
|
1124
|
+
return createPieChart(data, firstValueKey ?? "value", xKey, options);
|
|
1125
|
+
default:
|
|
1126
|
+
return createBarChart(
|
|
1127
|
+
data,
|
|
1128
|
+
xKey,
|
|
1129
|
+
yKeys.map((key) => ({ key })),
|
|
1130
|
+
options
|
|
1131
|
+
);
|
|
741
1132
|
}
|
|
742
1133
|
}
|
|
743
|
-
if (yKeys.length === 1 && typeof firstItem[xKey] === "string") {
|
|
744
|
-
return createPieChart(data,
|
|
1134
|
+
if (yKeys.length === 1 && firstValueKey && typeof firstItem[xKey] === "string") {
|
|
1135
|
+
return createPieChart(data, firstValueKey, xKey, options);
|
|
745
1136
|
}
|
|
746
1137
|
if (xKey.toLowerCase().includes("date") || xKey.toLowerCase().includes("time") || xKey.toLowerCase().includes("month") || xKey.toLowerCase().includes("year")) {
|
|
747
1138
|
return createLineChart(
|
|
@@ -773,234 +1164,13 @@ function resultWithCardGrid(cards, options) {
|
|
|
773
1164
|
function resultWithTable(data, columns, options) {
|
|
774
1165
|
return createToolResult(data, createTable(data, columns, options));
|
|
775
1166
|
}
|
|
776
|
-
|
|
777
|
-
// src/hooks/useAgnoChat.ts
|
|
778
|
-
var import_react5 = require("react");
|
|
779
|
-
function useAgnoChat() {
|
|
780
|
-
const client = useAgnoClient();
|
|
781
|
-
const [messages, setMessages] = (0, import_react5.useState)(client.getMessages());
|
|
782
|
-
const [state, setState] = (0, import_react5.useState)(client.getState());
|
|
783
|
-
const [error, setError] = (0, import_react5.useState)();
|
|
784
|
-
(0, import_react5.useEffect)(() => {
|
|
785
|
-
const handleMessageUpdate = (updatedMessages) => {
|
|
786
|
-
setMessages(updatedMessages);
|
|
787
|
-
};
|
|
788
|
-
const handleMessageComplete = (updatedMessages) => {
|
|
789
|
-
setMessages(updatedMessages);
|
|
790
|
-
};
|
|
791
|
-
const handleMessageRefreshed = (updatedMessages) => {
|
|
792
|
-
setMessages(updatedMessages);
|
|
793
|
-
};
|
|
794
|
-
const handleMessageError = (errorMessage) => {
|
|
795
|
-
setError(errorMessage);
|
|
796
|
-
};
|
|
797
|
-
const handleStateChange = (newState) => {
|
|
798
|
-
setState(newState);
|
|
799
|
-
};
|
|
800
|
-
const handleUIRender = (event) => {
|
|
801
|
-
const { tools } = event;
|
|
802
|
-
for (const tool of tools) {
|
|
803
|
-
if (tool.ui_component) {
|
|
804
|
-
client.hydrateToolCallUI(tool.tool_call_id, tool.ui_component);
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
};
|
|
808
|
-
client.on("message:update", handleMessageUpdate);
|
|
809
|
-
client.on("message:complete", handleMessageComplete);
|
|
810
|
-
client.on("message:refreshed", handleMessageRefreshed);
|
|
811
|
-
client.on("message:error", handleMessageError);
|
|
812
|
-
client.on("state:change", handleStateChange);
|
|
813
|
-
client.on("ui:render", handleUIRender);
|
|
814
|
-
setMessages(client.getMessages());
|
|
815
|
-
setState(client.getState());
|
|
816
|
-
return () => {
|
|
817
|
-
client.off("message:update", handleMessageUpdate);
|
|
818
|
-
client.off("message:complete", handleMessageComplete);
|
|
819
|
-
client.off("message:refreshed", handleMessageRefreshed);
|
|
820
|
-
client.off("message:error", handleMessageError);
|
|
821
|
-
client.off("state:change", handleStateChange);
|
|
822
|
-
client.off("ui:render", handleUIRender);
|
|
823
|
-
};
|
|
824
|
-
}, [client]);
|
|
825
|
-
const sendMessage = (0, import_react5.useCallback)(
|
|
826
|
-
async (message, options) => {
|
|
827
|
-
setError(void 0);
|
|
828
|
-
try {
|
|
829
|
-
await client.sendMessage(message, options);
|
|
830
|
-
} catch (err) {
|
|
831
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
832
|
-
setError(errorMessage);
|
|
833
|
-
throw err;
|
|
834
|
-
}
|
|
835
|
-
},
|
|
836
|
-
[client]
|
|
837
|
-
);
|
|
838
|
-
const clearMessages = (0, import_react5.useCallback)(() => {
|
|
839
|
-
client.clearMessages();
|
|
840
|
-
setMessages([]);
|
|
841
|
-
setError(void 0);
|
|
842
|
-
}, [client]);
|
|
843
|
-
return {
|
|
844
|
-
messages,
|
|
845
|
-
sendMessage,
|
|
846
|
-
clearMessages,
|
|
847
|
-
isStreaming: state.isStreaming,
|
|
848
|
-
isRefreshing: state.isRefreshing,
|
|
849
|
-
isPaused: state.isPaused,
|
|
850
|
-
error,
|
|
851
|
-
state
|
|
852
|
-
};
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
// src/hooks/useAgnoSession.ts
|
|
856
|
-
var import_react6 = require("react");
|
|
857
|
-
function useAgnoSession() {
|
|
858
|
-
const client = useAgnoClient();
|
|
859
|
-
const [sessions, setSessions] = (0, import_react6.useState)([]);
|
|
860
|
-
const [currentSessionId, setCurrentSessionId] = (0, import_react6.useState)(
|
|
861
|
-
client.getConfig().sessionId
|
|
862
|
-
);
|
|
863
|
-
const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
|
|
864
|
-
const [error, setError] = (0, import_react6.useState)();
|
|
865
|
-
(0, import_react6.useEffect)(() => {
|
|
866
|
-
const handleSessionLoaded = (sessionId) => {
|
|
867
|
-
setCurrentSessionId(sessionId);
|
|
868
|
-
};
|
|
869
|
-
const handleSessionCreated = (session) => {
|
|
870
|
-
setSessions((prev) => [session, ...prev]);
|
|
871
|
-
setCurrentSessionId(session.session_id);
|
|
872
|
-
};
|
|
873
|
-
const handleStateChange = () => {
|
|
874
|
-
const config = client.getConfig();
|
|
875
|
-
setCurrentSessionId(config.sessionId);
|
|
876
|
-
setSessions(client.getState().sessions);
|
|
877
|
-
};
|
|
878
|
-
client.on("session:loaded", handleSessionLoaded);
|
|
879
|
-
client.on("session:created", handleSessionCreated);
|
|
880
|
-
client.on("state:change", handleStateChange);
|
|
881
|
-
setSessions(client.getState().sessions);
|
|
882
|
-
setCurrentSessionId(client.getConfig().sessionId);
|
|
883
|
-
return () => {
|
|
884
|
-
client.off("session:loaded", handleSessionLoaded);
|
|
885
|
-
client.off("session:created", handleSessionCreated);
|
|
886
|
-
client.off("state:change", handleStateChange);
|
|
887
|
-
};
|
|
888
|
-
}, [client]);
|
|
889
|
-
const loadSession = (0, import_react6.useCallback)(
|
|
890
|
-
async (sessionId, options) => {
|
|
891
|
-
setIsLoading(true);
|
|
892
|
-
setError(void 0);
|
|
893
|
-
try {
|
|
894
|
-
const messages = await client.loadSession(sessionId, options);
|
|
895
|
-
setCurrentSessionId(sessionId);
|
|
896
|
-
return messages;
|
|
897
|
-
} catch (err) {
|
|
898
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
899
|
-
setError(errorMessage);
|
|
900
|
-
throw err;
|
|
901
|
-
} finally {
|
|
902
|
-
setIsLoading(false);
|
|
903
|
-
}
|
|
904
|
-
},
|
|
905
|
-
[client]
|
|
906
|
-
);
|
|
907
|
-
const fetchSessions = (0, import_react6.useCallback)(async (options) => {
|
|
908
|
-
setIsLoading(true);
|
|
909
|
-
setError(void 0);
|
|
910
|
-
try {
|
|
911
|
-
const fetchedSessions = await client.fetchSessions(options);
|
|
912
|
-
setSessions(fetchedSessions);
|
|
913
|
-
return fetchedSessions;
|
|
914
|
-
} catch (err) {
|
|
915
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
916
|
-
setError(errorMessage);
|
|
917
|
-
throw err;
|
|
918
|
-
} finally {
|
|
919
|
-
setIsLoading(false);
|
|
920
|
-
}
|
|
921
|
-
}, [client]);
|
|
922
|
-
return {
|
|
923
|
-
sessions,
|
|
924
|
-
currentSessionId,
|
|
925
|
-
loadSession,
|
|
926
|
-
fetchSessions,
|
|
927
|
-
isLoading,
|
|
928
|
-
error
|
|
929
|
-
};
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
// src/hooks/useAgnoActions.ts
|
|
933
|
-
var import_react7 = require("react");
|
|
934
|
-
function useAgnoActions() {
|
|
935
|
-
const client = useAgnoClient();
|
|
936
|
-
const [isInitializing, setIsInitializing] = (0, import_react7.useState)(false);
|
|
937
|
-
const [error, setError] = (0, import_react7.useState)();
|
|
938
|
-
const initialize = (0, import_react7.useCallback)(async (options) => {
|
|
939
|
-
setIsInitializing(true);
|
|
940
|
-
setError(void 0);
|
|
941
|
-
try {
|
|
942
|
-
const result = await client.initialize(options);
|
|
943
|
-
return result;
|
|
944
|
-
} catch (err) {
|
|
945
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
946
|
-
setError(errorMessage);
|
|
947
|
-
throw err;
|
|
948
|
-
} finally {
|
|
949
|
-
setIsInitializing(false);
|
|
950
|
-
}
|
|
951
|
-
}, [client]);
|
|
952
|
-
const checkStatus = (0, import_react7.useCallback)(async (options) => {
|
|
953
|
-
setError(void 0);
|
|
954
|
-
try {
|
|
955
|
-
return await client.checkStatus(options);
|
|
956
|
-
} catch (err) {
|
|
957
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
958
|
-
setError(errorMessage);
|
|
959
|
-
return false;
|
|
960
|
-
}
|
|
961
|
-
}, [client]);
|
|
962
|
-
const fetchAgents = (0, import_react7.useCallback)(async (options) => {
|
|
963
|
-
setError(void 0);
|
|
964
|
-
try {
|
|
965
|
-
return await client.fetchAgents(options);
|
|
966
|
-
} catch (err) {
|
|
967
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
968
|
-
setError(errorMessage);
|
|
969
|
-
throw err;
|
|
970
|
-
}
|
|
971
|
-
}, [client]);
|
|
972
|
-
const fetchTeams = (0, import_react7.useCallback)(async (options) => {
|
|
973
|
-
setError(void 0);
|
|
974
|
-
try {
|
|
975
|
-
return await client.fetchTeams(options);
|
|
976
|
-
} catch (err) {
|
|
977
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
978
|
-
setError(errorMessage);
|
|
979
|
-
throw err;
|
|
980
|
-
}
|
|
981
|
-
}, [client]);
|
|
982
|
-
const updateConfig = (0, import_react7.useCallback)(
|
|
983
|
-
(updates) => {
|
|
984
|
-
client.updateConfig(updates);
|
|
985
|
-
},
|
|
986
|
-
[client]
|
|
987
|
-
);
|
|
988
|
-
return {
|
|
989
|
-
initialize,
|
|
990
|
-
checkStatus,
|
|
991
|
-
fetchAgents,
|
|
992
|
-
fetchTeams,
|
|
993
|
-
updateConfig,
|
|
994
|
-
isInitializing,
|
|
995
|
-
error
|
|
996
|
-
};
|
|
997
|
-
}
|
|
998
1167
|
// Annotate the CommonJS export names for ESM import in node:
|
|
999
1168
|
0 && (module.exports = {
|
|
1000
1169
|
AgnoProvider,
|
|
1001
1170
|
ComponentRegistry,
|
|
1002
1171
|
GenerativeUIRenderer,
|
|
1003
1172
|
ToolHandlerProvider,
|
|
1173
|
+
clearCustomRenderRegistry,
|
|
1004
1174
|
createAreaChart,
|
|
1005
1175
|
createArtifact,
|
|
1006
1176
|
createBarChart,
|