@antipopp/agno-react 0.9.0 → 0.10.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/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() {
@@ -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,8 +154,65 @@ 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
- var import_react3 = require("react");
191
216
  var customRenderRegistry = /* @__PURE__ */ new Map();
192
217
  function registerCustomRender(renderFn) {
193
218
  const key = `custom-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
@@ -197,6 +222,9 @@ function registerCustomRender(renderFn) {
197
222
  function getCustomRender(key) {
198
223
  return customRenderRegistry.get(key);
199
224
  }
225
+ function clearCustomRenderRegistry() {
226
+ customRenderRegistry.clear();
227
+ }
200
228
  function isToolHandlerResult(value) {
201
229
  return value && typeof value === "object" && ("data" in value || "ui" in value);
202
230
  }
@@ -206,7 +234,7 @@ function isUIComponentSpec(value) {
206
234
  function processToolResult(result, _tool) {
207
235
  if (isToolHandlerResult(result)) {
208
236
  const { data, ui } = result;
209
- let uiComponent = void 0;
237
+ let uiComponent;
210
238
  if (ui) {
211
239
  if (ui.type === "custom" && typeof ui.render === "function") {
212
240
  const renderKey = registerCustomRender(ui.render);
@@ -345,14 +373,17 @@ function useAgnoToolExecution(handlers = {}, autoExecute = true) {
345
373
  const handleSessionLoaded = async (_sessionId) => {
346
374
  const messages = client.getMessages();
347
375
  for (const message of messages) {
348
- if (!message.tool_calls)
376
+ if (!message.tool_calls) {
349
377
  continue;
378
+ }
350
379
  for (const tool of message.tool_calls) {
351
- if (tool.ui_component)
380
+ if (tool.ui_component) {
352
381
  continue;
382
+ }
353
383
  const handler = mergedHandlers[tool.tool_name];
354
- if (!handler)
384
+ if (!handler) {
355
385
  continue;
386
+ }
356
387
  try {
357
388
  const result = await handler(tool.tool_args);
358
389
  const { uiComponent } = processToolResult(result, tool);
@@ -375,8 +406,9 @@ function useAgnoToolExecution(handlers = {}, autoExecute = true) {
375
406
  return Promise.all(
376
407
  tools.map(async (tool) => {
377
408
  const handler = mergedHandlers[tool.tool_name];
378
- if (!handler)
409
+ if (!handler) {
379
410
  return tool;
411
+ }
380
412
  try {
381
413
  const result = await handler(tool.tool_args);
382
414
  const { resultData, uiComponent } = processToolResult(result, tool);
@@ -417,7 +449,13 @@ function useAgnoToolExecution(handlers = {}, autoExecute = true) {
417
449
  if (autoExecute && isPaused && !isExecuting && pendingTools.length > 0) {
418
450
  executeAndContinue();
419
451
  }
420
- }, [autoExecute, isPaused, isExecuting, pendingTools.length, executeAndContinue]);
452
+ }, [
453
+ autoExecute,
454
+ isPaused,
455
+ isExecuting,
456
+ pendingTools.length,
457
+ executeAndContinue
458
+ ]);
421
459
  return {
422
460
  /** Whether the run is currently paused awaiting tool execution */
423
461
  isPaused,
@@ -447,14 +485,18 @@ var UIErrorBoundary = class extends import_react4.default.Component {
447
485
  return { hasError: true, error };
448
486
  }
449
487
  componentDidCatch(error, errorInfo) {
450
- console.error("[GenerativeUIRenderer] Error rendering component:", error, errorInfo);
488
+ console.error(
489
+ "[GenerativeUIRenderer] Error rendering component:",
490
+ error,
491
+ errorInfo
492
+ );
451
493
  this.props.onError?.(error);
452
494
  }
453
495
  render() {
454
496
  if (this.state.hasError) {
455
- 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: [
497
+ 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
498
  /* @__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 mt-1", children: this.state.error?.message || "Unknown error" })
499
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "mt-1 text-sm", children: this.state.error?.message || "Unknown error" })
458
500
  ] });
459
501
  }
460
502
  return this.props.children;
@@ -474,10 +516,16 @@ function GenerativeUIRenderer({
474
516
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UIErrorBoundary, { onError, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className, children: renderFn(customSpec.props || {}) }) });
475
517
  }
476
518
  }
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
- ] });
519
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
520
+ "div",
521
+ {
522
+ className: `rounded-md border border-yellow-300 bg-yellow-50 p-4 text-yellow-800 ${className || ""}`,
523
+ children: [
524
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "font-semibold", children: "Custom component not available" }),
525
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "mt-1 text-sm", children: "The custom render function for this component is not available." })
526
+ ]
527
+ }
528
+ );
481
529
  }
482
530
  if (spec.type === "chart") {
483
531
  const chartSpec = spec;
@@ -485,24 +533,30 @@ function GenerativeUIRenderer({
485
533
  if (registry.has(chartType)) {
486
534
  const ChartRenderer = registry.get(chartType);
487
535
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UIErrorBoundary, { onError, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className, children: [
488
- chartSpec.title && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "font-semibold mb-2", children: chartSpec.title }),
489
- chartSpec.description && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-sm text-gray-600 mb-4", children: chartSpec.description }),
536
+ chartSpec.title && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "mb-2 font-semibold", children: chartSpec.title }),
537
+ chartSpec.description && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "mb-4 text-gray-600 text-sm", children: chartSpec.description }),
490
538
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ChartRenderer, { ...chartSpec.props })
491
539
  ] }) });
492
540
  }
493
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: `p-4 border border-gray-300 rounded-md ${className || ""}`, children: [
494
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "font-semibold mb-2", children: chartSpec.title || "Chart Data" }),
495
- chartSpec.description && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-sm text-gray-600 mb-2", children: chartSpec.description }),
496
- /* @__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) })
497
- ] });
541
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
542
+ "div",
543
+ {
544
+ className: `rounded-md border border-gray-300 p-4 ${className || ""}`,
545
+ children: [
546
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "mb-2 font-semibold", children: chartSpec.title || "Chart Data" }),
547
+ chartSpec.description && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "mb-2 text-gray-600 text-sm", children: chartSpec.description }),
548
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { className: "overflow-auto rounded bg-gray-100 p-2 text-xs", children: JSON.stringify(chartSpec.props.data, null, 2) })
549
+ ]
550
+ }
551
+ );
498
552
  }
499
553
  if (spec.type === "card-grid") {
500
554
  const cardGridSpec = spec;
501
555
  if (registry.has("card-grid")) {
502
556
  const CardGridRenderer = registry.get("card-grid");
503
557
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UIErrorBoundary, { onError, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className, children: [
504
- cardGridSpec.title && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "font-semibold mb-2", children: cardGridSpec.title }),
505
- cardGridSpec.description && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-sm text-gray-600 mb-4", children: cardGridSpec.description }),
558
+ cardGridSpec.title && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "mb-2 font-semibold", children: cardGridSpec.title }),
559
+ cardGridSpec.description && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "mb-4 text-gray-600 text-sm", children: cardGridSpec.description }),
506
560
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CardGridRenderer, { ...cardGridSpec.props })
507
561
  ] }) });
508
562
  }
@@ -512,8 +566,8 @@ function GenerativeUIRenderer({
512
566
  if (registry.has("table")) {
513
567
  const TableRenderer = registry.get("table");
514
568
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UIErrorBoundary, { onError, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className, children: [
515
- tableSpec.title && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "font-semibold mb-2", children: tableSpec.title }),
516
- tableSpec.description && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-sm text-gray-600 mb-4", children: tableSpec.description }),
569
+ tableSpec.title && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "mb-2 font-semibold", children: tableSpec.title }),
570
+ tableSpec.description && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "mb-4 text-gray-600 text-sm", children: tableSpec.description }),
517
571
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TableRenderer, { ...tableSpec.props })
518
572
  ] }) });
519
573
  }
@@ -528,100 +582,361 @@ function GenerativeUIRenderer({
528
582
  }
529
583
  if (spec.type === "artifact") {
530
584
  const artifactSpec = spec;
531
- 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: [
532
- artifactSpec.title && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "font-semibold mb-4", children: artifactSpec.title }),
533
- artifactSpec.description && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-sm text-gray-600 mb-4", children: artifactSpec.description }),
534
- /* @__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)) })
585
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UIErrorBoundary, { onError, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: `rounded-md border p-4 ${className || ""}`, children: [
586
+ artifactSpec.title && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "mb-4 font-semibold", children: artifactSpec.title }),
587
+ artifactSpec.description && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "mb-4 text-gray-600 text-sm", children: artifactSpec.description }),
588
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "space-y-4", children: artifactSpec.props.content?.map(
589
+ (childSpec, index) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
590
+ GenerativeUIRenderer,
591
+ {
592
+ onError,
593
+ spec: childSpec
594
+ },
595
+ index
596
+ )
597
+ ) })
535
598
  ] }) });
536
599
  }
537
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: `p-4 border border-gray-300 rounded-md ${className || ""}`, children: [
600
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: `rounded-md border border-gray-300 p-4 ${className || ""}`, children: [
538
601
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "font-semibold", children: "Unsupported UI component" }),
539
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { className: "text-sm text-gray-600 mt-1", children: [
602
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { className: "mt-1 text-gray-600 text-sm", children: [
540
603
  "Component type: ",
541
604
  spec.type
542
605
  ] })
543
606
  ] });
544
607
  }
545
608
 
546
- // src/utils/ui-helpers.ts
547
- function createBarChart(data, xKey, bars, options) {
548
- return {
549
- type: "chart",
550
- component: "BarChart",
551
- layout: options?.layout,
552
- title: options?.title,
553
- description: options?.description,
554
- props: {
555
- data,
556
- xKey,
557
- bars: bars.map((bar) => ({
558
- key: bar.key,
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
- };
568
- }
569
- function createLineChart(data, xKey, lines, options) {
570
- return {
571
- type: "chart",
572
- component: "LineChart",
573
- layout: options?.layout,
574
- title: options?.title,
575
- description: options?.description,
576
- props: {
577
- data,
578
- xKey,
579
- lines: lines.map((line) => ({
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
- };
590
- }
591
- function createPieChart(data, dataKey, nameKey, options) {
609
+ // src/hooks/useAgnoActions.ts
610
+ var import_react5 = require("react");
611
+ function useAgnoActions() {
612
+ const client = useAgnoClient();
613
+ const [isInitializing, setIsInitializing] = (0, import_react5.useState)(false);
614
+ const [error, setError] = (0, import_react5.useState)();
615
+ const initialize = (0, import_react5.useCallback)(
616
+ async (options) => {
617
+ setIsInitializing(true);
618
+ setError(void 0);
619
+ try {
620
+ const result = await client.initialize(options);
621
+ return result;
622
+ } catch (err) {
623
+ const errorMessage = err instanceof Error ? err.message : String(err);
624
+ setError(errorMessage);
625
+ throw err;
626
+ } finally {
627
+ setIsInitializing(false);
628
+ }
629
+ },
630
+ [client]
631
+ );
632
+ const checkStatus = (0, import_react5.useCallback)(
633
+ async (options) => {
634
+ setError(void 0);
635
+ try {
636
+ return await client.checkStatus(options);
637
+ } catch (err) {
638
+ const errorMessage = err instanceof Error ? err.message : String(err);
639
+ setError(errorMessage);
640
+ return false;
641
+ }
642
+ },
643
+ [client]
644
+ );
645
+ const fetchAgents = (0, import_react5.useCallback)(
646
+ async (options) => {
647
+ setError(void 0);
648
+ try {
649
+ return await client.fetchAgents(options);
650
+ } catch (err) {
651
+ const errorMessage = err instanceof Error ? err.message : String(err);
652
+ setError(errorMessage);
653
+ throw err;
654
+ }
655
+ },
656
+ [client]
657
+ );
658
+ const fetchTeams = (0, import_react5.useCallback)(
659
+ async (options) => {
660
+ setError(void 0);
661
+ try {
662
+ return await client.fetchTeams(options);
663
+ } catch (err) {
664
+ const errorMessage = err instanceof Error ? err.message : String(err);
665
+ setError(errorMessage);
666
+ throw err;
667
+ }
668
+ },
669
+ [client]
670
+ );
671
+ const updateConfig = (0, import_react5.useCallback)(
672
+ (updates) => {
673
+ client.updateConfig(updates);
674
+ },
675
+ [client]
676
+ );
592
677
  return {
593
- type: "chart",
594
- component: "PieChart",
595
- layout: options?.layout,
596
- title: options?.title,
597
- description: options?.description,
598
- props: {
599
- data,
600
- pie: {
601
- dataKey,
602
- nameKey,
603
- label: options?.showLabel ?? true
604
- },
605
- showLegend: options?.showLegend ?? true,
606
- height: options?.height || 400,
607
- width: options?.width
608
- }
678
+ initialize,
679
+ checkStatus,
680
+ fetchAgents,
681
+ fetchTeams,
682
+ updateConfig,
683
+ isInitializing,
684
+ error
609
685
  };
610
686
  }
611
- function createAreaChart(data, xKey, areas, options) {
612
- return {
613
- type: "chart",
614
- component: "AreaChart",
615
- layout: options?.layout,
616
- title: options?.title,
617
- description: options?.description,
618
- props: {
619
- data,
620
- xKey,
621
- areas: areas.map((area) => ({
622
- key: area.key,
623
- label: area.label || area.key,
624
- color: area.color
687
+
688
+ // src/hooks/useAgnoChat.ts
689
+ var import_react6 = require("react");
690
+ function useAgnoChat() {
691
+ const client = useAgnoClient();
692
+ const [messages, setMessages] = (0, import_react6.useState)(client.getMessages());
693
+ const [state, setState] = (0, import_react6.useState)(client.getState());
694
+ const [error, setError] = (0, import_react6.useState)();
695
+ (0, import_react6.useEffect)(() => {
696
+ const handleMessageUpdate = (updatedMessages) => {
697
+ setMessages(updatedMessages);
698
+ };
699
+ const handleMessageComplete = (updatedMessages) => {
700
+ setMessages(updatedMessages);
701
+ };
702
+ const handleMessageRefreshed = (updatedMessages) => {
703
+ setMessages(updatedMessages);
704
+ };
705
+ const handleMessageError = (errorMessage) => {
706
+ setError(errorMessage);
707
+ };
708
+ const handleStateChange = (newState) => {
709
+ setState(newState);
710
+ };
711
+ const handleUIRender = (event) => {
712
+ const { tools } = event;
713
+ for (const tool of tools) {
714
+ if (tool.ui_component) {
715
+ client.hydrateToolCallUI(
716
+ tool.tool_call_id,
717
+ tool.ui_component
718
+ );
719
+ }
720
+ }
721
+ };
722
+ client.on("message:update", handleMessageUpdate);
723
+ client.on("message:complete", handleMessageComplete);
724
+ client.on("message:refreshed", handleMessageRefreshed);
725
+ client.on("message:error", handleMessageError);
726
+ client.on("state:change", handleStateChange);
727
+ client.on("ui:render", handleUIRender);
728
+ setMessages(client.getMessages());
729
+ setState(client.getState());
730
+ return () => {
731
+ client.off("message:update", handleMessageUpdate);
732
+ client.off("message:complete", handleMessageComplete);
733
+ client.off("message:refreshed", handleMessageRefreshed);
734
+ client.off("message:error", handleMessageError);
735
+ client.off("state:change", handleStateChange);
736
+ client.off("ui:render", handleUIRender);
737
+ };
738
+ }, [client]);
739
+ const sendMessage = (0, import_react6.useCallback)(
740
+ async (message, options) => {
741
+ setError(void 0);
742
+ try {
743
+ await client.sendMessage(message, options);
744
+ } catch (err) {
745
+ const errorMessage = err instanceof Error ? err.message : String(err);
746
+ setError(errorMessage);
747
+ throw err;
748
+ }
749
+ },
750
+ [client]
751
+ );
752
+ const cancelRun = (0, import_react6.useCallback)(async () => {
753
+ try {
754
+ await client.cancelRun();
755
+ } catch (err) {
756
+ const errorMessage = err instanceof Error ? err.message : String(err);
757
+ setError(errorMessage);
758
+ throw err;
759
+ }
760
+ }, [client]);
761
+ const clearMessages = (0, import_react6.useCallback)(() => {
762
+ client.clearMessages();
763
+ setMessages([]);
764
+ setError(void 0);
765
+ }, [client]);
766
+ return {
767
+ messages,
768
+ sendMessage,
769
+ clearMessages,
770
+ cancelRun,
771
+ isStreaming: state.isStreaming,
772
+ isRefreshing: state.isRefreshing,
773
+ isPaused: state.isPaused,
774
+ isCancelling: state.isCancelling,
775
+ currentRunId: state.currentRunId,
776
+ error,
777
+ state
778
+ };
779
+ }
780
+
781
+ // src/hooks/useAgnoSession.ts
782
+ var import_react7 = require("react");
783
+ function useAgnoSession() {
784
+ const client = useAgnoClient();
785
+ const [sessions, setSessions] = (0, import_react7.useState)([]);
786
+ const [currentSessionId, setCurrentSessionId] = (0, import_react7.useState)(
787
+ client.getConfig().sessionId
788
+ );
789
+ const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
790
+ const [error, setError] = (0, import_react7.useState)();
791
+ (0, import_react7.useEffect)(() => {
792
+ const handleSessionLoaded = (sessionId) => {
793
+ setCurrentSessionId(sessionId);
794
+ };
795
+ const handleSessionCreated = (session) => {
796
+ setSessions((prev) => [session, ...prev]);
797
+ setCurrentSessionId(session.session_id);
798
+ };
799
+ const handleStateChange = () => {
800
+ const config = client.getConfig();
801
+ setCurrentSessionId(config.sessionId);
802
+ setSessions(client.getState().sessions);
803
+ };
804
+ client.on("session:loaded", handleSessionLoaded);
805
+ client.on("session:created", handleSessionCreated);
806
+ client.on("state:change", handleStateChange);
807
+ setSessions(client.getState().sessions);
808
+ setCurrentSessionId(client.getConfig().sessionId);
809
+ return () => {
810
+ client.off("session:loaded", handleSessionLoaded);
811
+ client.off("session:created", handleSessionCreated);
812
+ client.off("state:change", handleStateChange);
813
+ };
814
+ }, [client]);
815
+ const loadSession = (0, import_react7.useCallback)(
816
+ async (sessionId, options) => {
817
+ setIsLoading(true);
818
+ setError(void 0);
819
+ try {
820
+ const messages = await client.loadSession(sessionId, options);
821
+ setCurrentSessionId(sessionId);
822
+ return messages;
823
+ } catch (err) {
824
+ const errorMessage = err instanceof Error ? err.message : String(err);
825
+ setError(errorMessage);
826
+ throw err;
827
+ } finally {
828
+ setIsLoading(false);
829
+ }
830
+ },
831
+ [client]
832
+ );
833
+ const fetchSessions = (0, import_react7.useCallback)(
834
+ async (options) => {
835
+ setIsLoading(true);
836
+ setError(void 0);
837
+ try {
838
+ const fetchedSessions = await client.fetchSessions(options);
839
+ setSessions(fetchedSessions);
840
+ return fetchedSessions;
841
+ } catch (err) {
842
+ const errorMessage = err instanceof Error ? err.message : String(err);
843
+ setError(errorMessage);
844
+ throw err;
845
+ } finally {
846
+ setIsLoading(false);
847
+ }
848
+ },
849
+ [client]
850
+ );
851
+ return {
852
+ sessions,
853
+ currentSessionId,
854
+ loadSession,
855
+ fetchSessions,
856
+ isLoading,
857
+ error
858
+ };
859
+ }
860
+
861
+ // src/utils/ui-helpers.ts
862
+ function createBarChart(data, xKey, bars, options) {
863
+ return {
864
+ type: "chart",
865
+ component: "BarChart",
866
+ layout: options?.layout,
867
+ title: options?.title,
868
+ description: options?.description,
869
+ props: {
870
+ data,
871
+ xKey,
872
+ bars: bars.map((bar) => ({
873
+ key: bar.key,
874
+ label: bar.label || bar.key,
875
+ color: bar.color
876
+ })),
877
+ showLegend: options?.showLegend ?? true,
878
+ showGrid: options?.showGrid ?? true,
879
+ height: options?.height,
880
+ width: options?.width
881
+ }
882
+ };
883
+ }
884
+ function createLineChart(data, xKey, lines, options) {
885
+ return {
886
+ type: "chart",
887
+ component: "LineChart",
888
+ layout: options?.layout,
889
+ title: options?.title,
890
+ description: options?.description,
891
+ props: {
892
+ data,
893
+ xKey,
894
+ lines: lines.map((line) => ({
895
+ key: line.key,
896
+ label: line.label || line.key,
897
+ color: line.color
898
+ })),
899
+ showLegend: options?.showLegend ?? true,
900
+ showGrid: options?.showGrid ?? true,
901
+ height: options?.height,
902
+ width: options?.width
903
+ }
904
+ };
905
+ }
906
+ function createPieChart(data, dataKey, nameKey, options) {
907
+ return {
908
+ type: "chart",
909
+ component: "PieChart",
910
+ layout: options?.layout,
911
+ title: options?.title,
912
+ description: options?.description,
913
+ props: {
914
+ data,
915
+ pie: {
916
+ dataKey,
917
+ nameKey,
918
+ label: options?.showLabel ?? true
919
+ },
920
+ showLegend: options?.showLegend ?? true,
921
+ height: options?.height || 400,
922
+ width: options?.width
923
+ }
924
+ };
925
+ }
926
+ function createAreaChart(data, xKey, areas, options) {
927
+ return {
928
+ type: "chart",
929
+ component: "AreaChart",
930
+ layout: options?.layout,
931
+ title: options?.title,
932
+ description: options?.description,
933
+ props: {
934
+ data,
935
+ xKey,
936
+ areas: areas.map((area) => ({
937
+ key: area.key,
938
+ label: area.label || area.key,
939
+ color: area.color
625
940
  })),
626
941
  showLegend: options?.showLegend ?? true,
627
942
  showGrid: options?.showGrid ?? true,
@@ -709,9 +1024,13 @@ function createSmartChart(data, options) {
709
1024
  const firstItem = data[0];
710
1025
  const keys = Object.keys(firstItem);
711
1026
  const xKey = options?.xKey || keys.find(
712
- (k) => ["name", "label", "category", "date", "time", "month", "year"].includes(k.toLowerCase())
1027
+ (k) => ["name", "label", "category", "date", "time", "month", "year"].includes(
1028
+ k.toLowerCase()
1029
+ )
713
1030
  ) || keys[0];
714
- const numericKeys = keys.filter((k) => k !== xKey && typeof firstItem[k] === "number");
1031
+ const numericKeys = keys.filter(
1032
+ (k) => k !== xKey && typeof firstItem[k] === "number"
1033
+ );
715
1034
  const yKeys = options?.yKeys || numericKeys;
716
1035
  if (options?.preferredType) {
717
1036
  switch (options.preferredType) {
@@ -773,234 +1092,13 @@ function resultWithCardGrid(cards, options) {
773
1092
  function resultWithTable(data, columns, options) {
774
1093
  return createToolResult(data, createTable(data, columns, options));
775
1094
  }
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
1095
  // Annotate the CommonJS export names for ESM import in node:
999
1096
  0 && (module.exports = {
1000
1097
  AgnoProvider,
1001
1098
  ComponentRegistry,
1002
1099
  GenerativeUIRenderer,
1003
1100
  ToolHandlerProvider,
1101
+ clearCustomRenderRegistry,
1004
1102
  createAreaChart,
1005
1103
  createArtifact,
1006
1104
  createBarChart,