@rodrigocoliveira/agno-react 1.0.2 → 1.1.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 +2 -2
- package/dist/components/GenerativeUIRenderer.d.ts +21 -0
- package/dist/components/GenerativeUIRenderer.d.ts.map +1 -0
- package/dist/context/AgnoContext.d.ts +16 -0
- package/dist/context/AgnoContext.d.ts.map +1 -0
- package/dist/context/ToolHandlerContext.d.ts +44 -0
- package/dist/context/ToolHandlerContext.d.ts.map +1 -0
- package/dist/hooks/useAgnoActions.d.ts +25 -0
- package/dist/hooks/useAgnoActions.d.ts.map +1 -0
- package/dist/hooks/useAgnoChat.d.ts +22 -0
- package/dist/hooks/useAgnoChat.d.ts.map +1 -0
- package/dist/hooks/useAgnoCustomEvents.d.ts +38 -0
- package/dist/hooks/useAgnoCustomEvents.d.ts.map +1 -0
- package/dist/hooks/useAgnoEvals.d.ts +39 -0
- package/dist/hooks/useAgnoEvals.d.ts.map +1 -0
- package/dist/hooks/useAgnoKnowledge.d.ts +56 -0
- package/dist/hooks/useAgnoKnowledge.d.ts.map +1 -0
- package/dist/hooks/useAgnoMemory.d.ts +42 -0
- package/dist/hooks/useAgnoMemory.d.ts.map +1 -0
- package/dist/hooks/useAgnoMetrics.d.ts +51 -0
- package/dist/hooks/useAgnoMetrics.d.ts.map +1 -0
- package/dist/hooks/useAgnoSession.d.ts +38 -0
- package/dist/hooks/useAgnoSession.d.ts.map +1 -0
- package/dist/hooks/useAgnoToolExecution.d.ts +70 -0
- package/dist/hooks/useAgnoToolExecution.d.ts.map +1 -0
- package/dist/hooks/useAgnoTraces.d.ts +51 -0
- package/dist/hooks/useAgnoTraces.d.ts.map +1 -0
- package/dist/index.d.ts +27 -723
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +924 -1060
- package/dist/index.js.map +24 -0
- package/dist/index.mjs +814 -923
- package/dist/index.mjs.map +24 -0
- package/dist/ui/components/artifact.d.ts +24 -0
- package/dist/ui/components/artifact.d.ts.map +1 -0
- package/dist/ui/components/audio-recorder.d.ts +32 -0
- package/dist/ui/components/audio-recorder.d.ts.map +1 -0
- package/dist/ui/components/code-block.d.ts +15 -0
- package/dist/ui/components/code-block.d.ts.map +1 -0
- package/dist/ui/components/conversation.d.ts +17 -0
- package/dist/ui/components/conversation.d.ts.map +1 -0
- package/dist/ui/components/file-preview-card.d.ts +13 -0
- package/dist/ui/components/file-preview-card.d.ts.map +1 -0
- package/dist/ui/components/file-preview-modal.d.ts +8 -0
- package/dist/ui/components/file-preview-modal.d.ts.map +1 -0
- package/dist/ui/components/image-lightbox.d.ts +12 -0
- package/dist/ui/components/image-lightbox.d.ts.map +1 -0
- package/dist/ui/components/message.d.ts +19 -0
- package/dist/ui/components/message.d.ts.map +1 -0
- package/dist/ui/components/prompt-input/attachments.d.ts +21 -0
- package/dist/ui/components/prompt-input/attachments.d.ts.map +1 -0
- package/dist/ui/components/prompt-input/buttons.d.ts +19 -0
- package/dist/ui/components/prompt-input/buttons.d.ts.map +1 -0
- package/dist/ui/components/prompt-input/command.d.ts +17 -0
- package/dist/ui/components/prompt-input/command.d.ts.map +1 -0
- package/dist/ui/components/prompt-input/context.d.ts +36 -0
- package/dist/ui/components/prompt-input/context.d.ts.map +1 -0
- package/dist/ui/components/prompt-input/drop-zone.d.ts +7 -0
- package/dist/ui/components/prompt-input/drop-zone.d.ts.map +1 -0
- package/dist/ui/components/prompt-input/footer.d.ts +11 -0
- package/dist/ui/components/prompt-input/footer.d.ts.map +1 -0
- package/dist/ui/components/prompt-input/index.d.ts +25 -0
- package/dist/ui/components/prompt-input/index.d.ts.map +1 -0
- package/dist/ui/components/prompt-input/model-select.d.ts +13 -0
- package/dist/ui/components/prompt-input/model-select.d.ts.map +1 -0
- package/dist/ui/components/prompt-input/prompt-input.d.ts +22 -0
- package/dist/ui/components/prompt-input/prompt-input.d.ts.map +1 -0
- package/dist/ui/components/prompt-input/provider.d.ts +6 -0
- package/dist/ui/components/prompt-input/provider.d.ts.map +1 -0
- package/dist/ui/components/prompt-input/speech.d.ts +51 -0
- package/dist/ui/components/prompt-input/speech.d.ts.map +1 -0
- package/dist/ui/components/prompt-input/tabs.d.ts +12 -0
- package/dist/ui/components/prompt-input/tabs.d.ts.map +1 -0
- package/dist/ui/components/prompt-input/textarea.d.ts +5 -0
- package/dist/ui/components/prompt-input/textarea.d.ts.map +1 -0
- package/dist/ui/components/response.d.ts +5 -0
- package/dist/ui/components/response.d.ts.map +1 -0
- package/dist/ui/components/smart-timestamp.d.ts +8 -0
- package/dist/ui/components/smart-timestamp.d.ts.map +1 -0
- package/dist/ui/components/streaming-indicator.d.ts +8 -0
- package/dist/ui/components/streaming-indicator.d.ts.map +1 -0
- package/dist/ui/components/tool.d.ts +24 -0
- package/dist/ui/components/tool.d.ts.map +1 -0
- package/dist/ui/composed/AgnoChatInput.d.ts +38 -0
- package/dist/ui/composed/AgnoChatInput.d.ts.map +1 -0
- package/dist/ui/composed/AgnoMessageItem.d.ts +38 -0
- package/dist/ui/composed/AgnoMessageItem.d.ts.map +1 -0
- package/dist/ui/composed/agno-chat/agno-chat.d.ts +9 -0
- package/dist/ui/composed/agno-chat/agno-chat.d.ts.map +1 -0
- package/dist/ui/composed/agno-chat/context.d.ts +33 -0
- package/dist/ui/composed/agno-chat/context.d.ts.map +1 -0
- package/dist/ui/composed/agno-chat/empty-state.d.ts +6 -0
- package/dist/ui/composed/agno-chat/empty-state.d.ts.map +1 -0
- package/dist/ui/composed/agno-chat/error-bar.d.ts +16 -0
- package/dist/ui/composed/agno-chat/error-bar.d.ts.map +1 -0
- package/dist/ui/composed/agno-chat/index.d.ts +33 -0
- package/dist/ui/composed/agno-chat/index.d.ts.map +1 -0
- package/dist/ui/composed/agno-chat/input.d.ts +34 -0
- package/dist/ui/composed/agno-chat/input.d.ts.map +1 -0
- package/dist/ui/composed/agno-chat/messages.d.ts +45 -0
- package/dist/ui/composed/agno-chat/messages.d.ts.map +1 -0
- package/dist/ui/composed/agno-chat/suggested-prompts.d.ts +7 -0
- package/dist/ui/composed/agno-chat/suggested-prompts.d.ts.map +1 -0
- package/dist/ui/composed/agno-chat/tool-status.d.ts +5 -0
- package/dist/ui/composed/agno-chat/tool-status.d.ts.map +1 -0
- package/dist/ui/composed/index.d.ts +7 -0
- package/dist/ui/composed/index.d.ts.map +1 -0
- package/dist/ui/index.d.ts +57 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/lib/cn.d.ts +3 -0
- package/dist/ui/lib/cn.d.ts.map +1 -0
- package/dist/ui/lib/file-utils.d.ts +20 -0
- package/dist/ui/lib/file-utils.d.ts.map +1 -0
- package/dist/ui/lib/format-timestamp.d.ts +16 -0
- package/dist/ui/lib/format-timestamp.d.ts.map +1 -0
- package/dist/ui/primitives/accordion.d.ts +8 -0
- package/dist/ui/primitives/accordion.d.ts.map +1 -0
- package/dist/ui/primitives/avatar.d.ts +7 -0
- package/dist/ui/primitives/avatar.d.ts.map +1 -0
- package/dist/ui/primitives/badge.d.ts +10 -0
- package/dist/ui/primitives/badge.d.ts.map +1 -0
- package/dist/ui/primitives/button.d.ts +12 -0
- package/dist/ui/primitives/button.d.ts.map +1 -0
- package/dist/ui/primitives/collapsible.d.ts +6 -0
- package/dist/ui/primitives/collapsible.d.ts.map +1 -0
- package/dist/ui/primitives/command.d.ts +79 -0
- package/dist/ui/primitives/command.d.ts.map +1 -0
- package/dist/ui/primitives/dialog.d.ts +26 -0
- package/dist/ui/primitives/dialog.d.ts.map +1 -0
- package/dist/ui/primitives/dropdown-menu.d.ts +28 -0
- package/dist/ui/primitives/dropdown-menu.d.ts.map +1 -0
- package/dist/ui/primitives/hover-card.d.ts +7 -0
- package/dist/ui/primitives/hover-card.d.ts.map +1 -0
- package/dist/ui/primitives/index.d.ts +16 -0
- package/dist/ui/primitives/index.d.ts.map +1 -0
- package/dist/ui/primitives/input-group.d.ts +17 -0
- package/dist/ui/primitives/input-group.d.ts.map +1 -0
- package/dist/ui/primitives/select.d.ts +14 -0
- package/dist/ui/primitives/select.d.ts.map +1 -0
- package/dist/ui/primitives/tooltip.d.ts +8 -0
- package/dist/ui/primitives/tooltip.d.ts.map +1 -0
- package/dist/ui/types.d.ts +91 -0
- package/dist/ui/types.d.ts.map +1 -0
- package/dist/ui.d.ts +2 -891
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +2963 -2496
- package/dist/ui.js.map +59 -0
- package/dist/ui.mjs +2854 -2232
- package/dist/ui.mjs.map +59 -0
- package/dist/utils/component-registry.d.ts +63 -0
- package/dist/utils/component-registry.d.ts.map +1 -0
- package/dist/utils/ui-helpers.d.ts +165 -0
- package/dist/utils/ui-helpers.d.ts.map +1 -0
- package/package.json +9 -10
- package/LICENSE +0 -21
- package/dist/index.d.mts +0 -724
- package/dist/ui.d.mts +0 -891
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/context/AgnoContext.tsx
|
|
2
2
|
import { createContext, useContext, useMemo, useEffect } from "react";
|
|
3
3
|
import { AgnoClient } from "@rodrigocoliveira/agno-client";
|
|
4
|
-
import {
|
|
4
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
5
5
|
var AgnoContext = createContext(null);
|
|
6
6
|
function AgnoProvider({ config, children }) {
|
|
7
7
|
const client = useMemo(() => new AgnoClient(config), []);
|
|
@@ -13,7 +13,10 @@ function AgnoProvider({ config, children }) {
|
|
|
13
13
|
client.removeAllListeners();
|
|
14
14
|
};
|
|
15
15
|
}, [client]);
|
|
16
|
-
return /* @__PURE__ */
|
|
16
|
+
return /* @__PURE__ */ jsxDEV(AgnoContext.Provider, {
|
|
17
|
+
value: client,
|
|
18
|
+
children
|
|
19
|
+
}, undefined, false, undefined, this);
|
|
17
20
|
}
|
|
18
21
|
function useAgnoClient() {
|
|
19
22
|
const client = useContext(AgnoContext);
|
|
@@ -22,10 +25,9 @@ function useAgnoClient() {
|
|
|
22
25
|
}
|
|
23
26
|
return client;
|
|
24
27
|
}
|
|
25
|
-
|
|
26
28
|
// src/context/ToolHandlerContext.tsx
|
|
27
29
|
import { createContext as createContext2, useContext as useContext2, useState, useCallback } from "react";
|
|
28
|
-
import {
|
|
30
|
+
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
29
31
|
var ToolHandlerContext = createContext2(null);
|
|
30
32
|
function ToolHandlerProvider({ handlers: initialHandlers = {}, children }) {
|
|
31
33
|
const [handlers, setHandlers] = useState(initialHandlers);
|
|
@@ -43,74 +45,52 @@ function ToolHandlerProvider({ handlers: initialHandlers = {}, children }) {
|
|
|
43
45
|
registerHandler,
|
|
44
46
|
unregisterHandler
|
|
45
47
|
};
|
|
46
|
-
return /* @__PURE__ */
|
|
48
|
+
return /* @__PURE__ */ jsxDEV2(ToolHandlerContext.Provider, {
|
|
49
|
+
value,
|
|
50
|
+
children
|
|
51
|
+
}, undefined, false, undefined, this);
|
|
47
52
|
}
|
|
48
53
|
function useToolHandlers() {
|
|
49
54
|
return useContext2(ToolHandlerContext);
|
|
50
55
|
}
|
|
51
|
-
|
|
52
56
|
// src/components/GenerativeUIRenderer.tsx
|
|
53
57
|
import React3 from "react";
|
|
54
58
|
|
|
55
59
|
// src/utils/component-registry.ts
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Get the singleton instance
|
|
62
|
-
*/
|
|
60
|
+
class ComponentRegistry {
|
|
61
|
+
static instance;
|
|
62
|
+
components = new Map;
|
|
63
|
+
constructor() {}
|
|
63
64
|
static getInstance() {
|
|
64
|
-
if (!
|
|
65
|
-
|
|
65
|
+
if (!ComponentRegistry.instance) {
|
|
66
|
+
ComponentRegistry.instance = new ComponentRegistry;
|
|
66
67
|
}
|
|
67
|
-
return
|
|
68
|
+
return ComponentRegistry.instance;
|
|
68
69
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Register a component renderer
|
|
71
|
-
*/
|
|
72
70
|
register(type, renderer) {
|
|
73
71
|
this.components.set(type, renderer);
|
|
74
72
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Register multiple components at once
|
|
77
|
-
*/
|
|
78
73
|
registerBatch(components) {
|
|
79
74
|
Object.entries(components).forEach(([type, renderer]) => {
|
|
80
75
|
this.register(type, renderer);
|
|
81
76
|
});
|
|
82
77
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Get a registered component renderer
|
|
85
|
-
*/
|
|
86
78
|
get(type) {
|
|
87
79
|
return this.components.get(type);
|
|
88
80
|
}
|
|
89
|
-
/**
|
|
90
|
-
* Check if a component is registered
|
|
91
|
-
*/
|
|
92
81
|
has(type) {
|
|
93
82
|
return this.components.has(type);
|
|
94
83
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Unregister a component
|
|
97
|
-
*/
|
|
98
84
|
unregister(type) {
|
|
99
85
|
this.components.delete(type);
|
|
100
86
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Get all registered component types
|
|
103
|
-
*/
|
|
104
87
|
getRegisteredTypes() {
|
|
105
88
|
return Array.from(this.components.keys());
|
|
106
89
|
}
|
|
107
|
-
/**
|
|
108
|
-
* Clear all registered components
|
|
109
|
-
*/
|
|
110
90
|
clear() {
|
|
111
91
|
this.components.clear();
|
|
112
92
|
}
|
|
113
|
-
}
|
|
93
|
+
}
|
|
114
94
|
function getComponentRegistry() {
|
|
115
95
|
return ComponentRegistry.getInstance();
|
|
116
96
|
}
|
|
@@ -123,7 +103,7 @@ function getChartComponent(name) {
|
|
|
123
103
|
|
|
124
104
|
// src/hooks/useAgnoToolExecution.ts
|
|
125
105
|
import { useState as useState2, useEffect as useEffect2, useCallback as useCallback2, useMemo as useMemo2 } from "react";
|
|
126
|
-
var customRenderRegistry =
|
|
106
|
+
var customRenderRegistry = new Map;
|
|
127
107
|
function registerCustomRender(renderFn) {
|
|
128
108
|
const key = `custom-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
129
109
|
customRenderRegistry.set(key, renderFn);
|
|
@@ -133,7 +113,7 @@ function getCustomRender(key) {
|
|
|
133
113
|
return customRenderRegistry.get(key);
|
|
134
114
|
}
|
|
135
115
|
function isToolHandlerResult(value) {
|
|
136
|
-
return value && typeof value === "object" && ("data" in value || "ui" in value);
|
|
116
|
+
return value && typeof value === "object" && (("data" in value) || ("ui" in value));
|
|
137
117
|
}
|
|
138
118
|
function isUIComponentSpec(value) {
|
|
139
119
|
return value && typeof value === "object" && "type" in value;
|
|
@@ -141,15 +121,14 @@ function isUIComponentSpec(value) {
|
|
|
141
121
|
function processToolResult(result, _tool) {
|
|
142
122
|
if (isToolHandlerResult(result)) {
|
|
143
123
|
const { data, ui } = result;
|
|
144
|
-
let uiComponent =
|
|
124
|
+
let uiComponent = undefined;
|
|
145
125
|
if (ui) {
|
|
146
126
|
if (ui.type === "custom" && typeof ui.render === "function") {
|
|
147
127
|
const renderKey = registerCustomRender(ui.render);
|
|
148
128
|
uiComponent = {
|
|
149
129
|
...ui,
|
|
150
130
|
renderKey,
|
|
151
|
-
render:
|
|
152
|
-
// Don't store the function itself
|
|
131
|
+
render: undefined
|
|
153
132
|
};
|
|
154
133
|
} else {
|
|
155
134
|
uiComponent = ui;
|
|
@@ -167,7 +146,7 @@ function processToolResult(result, _tool) {
|
|
|
167
146
|
uiComponent = {
|
|
168
147
|
...result,
|
|
169
148
|
renderKey,
|
|
170
|
-
render:
|
|
149
|
+
render: undefined
|
|
171
150
|
};
|
|
172
151
|
} else {
|
|
173
152
|
uiComponent = result;
|
|
@@ -179,7 +158,7 @@ function processToolResult(result, _tool) {
|
|
|
179
158
|
}
|
|
180
159
|
return {
|
|
181
160
|
resultData: typeof result === "string" ? result : JSON.stringify(result),
|
|
182
|
-
uiComponent:
|
|
161
|
+
uiComponent: undefined
|
|
183
162
|
};
|
|
184
163
|
}
|
|
185
164
|
function useAgnoToolExecution(handlers = {}, autoExecute = true) {
|
|
@@ -188,9 +167,7 @@ function useAgnoToolExecution(handlers = {}, autoExecute = true) {
|
|
|
188
167
|
const isTeamMode = client.getConfig().mode === "team";
|
|
189
168
|
useEffect2(() => {
|
|
190
169
|
if (isTeamMode) {
|
|
191
|
-
console.warn(
|
|
192
|
-
"[useAgnoToolExecution] HITL (Human-in-the-Loop) frontend tool execution is not supported for teams. Only agents support the continue endpoint. This hook will not function in team mode."
|
|
193
|
-
);
|
|
170
|
+
console.warn("[useAgnoToolExecution] HITL (Human-in-the-Loop) frontend tool execution is not supported for teams. " + "Only agents support the continue endpoint. This hook will not function in team mode.");
|
|
194
171
|
}
|
|
195
172
|
}, [isTeamMode]);
|
|
196
173
|
const mergedHandlers = useMemo2(() => {
|
|
@@ -208,13 +185,13 @@ function useAgnoToolExecution(handlers = {}, autoExecute = true) {
|
|
|
208
185
|
const handleRunPaused = (event) => {
|
|
209
186
|
setIsPaused(true);
|
|
210
187
|
setPendingTools(event.tools);
|
|
211
|
-
setExecutionError(
|
|
188
|
+
setExecutionError(undefined);
|
|
212
189
|
};
|
|
213
190
|
const handleRunContinued = () => {
|
|
214
191
|
setIsPaused(false);
|
|
215
192
|
setPendingTools([]);
|
|
216
193
|
setIsExecuting(false);
|
|
217
|
-
setExecutionError(
|
|
194
|
+
setExecutionError(undefined);
|
|
218
195
|
};
|
|
219
196
|
client.on("run:paused", handleRunPaused);
|
|
220
197
|
client.on("run:continued", handleRunContinued);
|
|
@@ -229,37 +206,35 @@ function useAgnoToolExecution(handlers = {}, autoExecute = true) {
|
|
|
229
206
|
return;
|
|
230
207
|
}
|
|
231
208
|
setIsExecuting(true);
|
|
232
|
-
setExecutionError(
|
|
209
|
+
setExecutionError(undefined);
|
|
233
210
|
try {
|
|
234
|
-
const updatedTools = await Promise.all(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
})
|
|
262
|
-
);
|
|
211
|
+
const updatedTools = await Promise.all(pendingTools.map(async (tool) => {
|
|
212
|
+
const handler = mergedHandlers[tool.tool_name];
|
|
213
|
+
if (!handler) {
|
|
214
|
+
return {
|
|
215
|
+
...tool,
|
|
216
|
+
result: JSON.stringify({
|
|
217
|
+
error: `No handler registered for ${tool.tool_name}`
|
|
218
|
+
})
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
const result = await handler(tool.tool_args);
|
|
223
|
+
const { resultData, uiComponent } = processToolResult(result, tool);
|
|
224
|
+
return {
|
|
225
|
+
...tool,
|
|
226
|
+
result: resultData,
|
|
227
|
+
ui_component: uiComponent
|
|
228
|
+
};
|
|
229
|
+
} catch (error) {
|
|
230
|
+
return {
|
|
231
|
+
...tool,
|
|
232
|
+
result: JSON.stringify({
|
|
233
|
+
error: error instanceof Error ? error.message : String(error)
|
|
234
|
+
})
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}));
|
|
263
238
|
const toolsWithUI = updatedTools.filter((t) => t.ui_component);
|
|
264
239
|
if (toolsWithUI.length > 0) {
|
|
265
240
|
client.emit("ui:render", {
|
|
@@ -280,11 +255,14 @@ function useAgnoToolExecution(handlers = {}, autoExecute = true) {
|
|
|
280
255
|
const handleSessionLoaded = async (_sessionId) => {
|
|
281
256
|
const messages = client.getMessages();
|
|
282
257
|
for (const message of messages) {
|
|
283
|
-
if (!message.tool_calls)
|
|
258
|
+
if (!message.tool_calls)
|
|
259
|
+
continue;
|
|
284
260
|
for (const tool of message.tool_calls) {
|
|
285
|
-
if (tool.ui_component)
|
|
261
|
+
if (tool.ui_component)
|
|
262
|
+
continue;
|
|
286
263
|
const handler = mergedHandlers[tool.tool_name];
|
|
287
|
-
if (!handler)
|
|
264
|
+
if (!handler)
|
|
265
|
+
continue;
|
|
288
266
|
try {
|
|
289
267
|
const result = await handler(tool.tool_args);
|
|
290
268
|
const { uiComponent } = processToolResult(result, tool);
|
|
@@ -302,74 +280,61 @@ function useAgnoToolExecution(handlers = {}, autoExecute = true) {
|
|
|
302
280
|
client.off("session:loaded", handleSessionLoaded);
|
|
303
281
|
};
|
|
304
282
|
}, [client, mergedHandlers]);
|
|
305
|
-
const executeTools = useCallback2(
|
|
306
|
-
async (
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
if (!handler) return tool;
|
|
311
|
-
try {
|
|
312
|
-
const result = await handler(tool.tool_args);
|
|
313
|
-
const { resultData, uiComponent } = processToolResult(result, tool);
|
|
314
|
-
return {
|
|
315
|
-
...tool,
|
|
316
|
-
result: resultData,
|
|
317
|
-
ui_component: uiComponent
|
|
318
|
-
};
|
|
319
|
-
} catch (error) {
|
|
320
|
-
return {
|
|
321
|
-
...tool,
|
|
322
|
-
result: JSON.stringify({
|
|
323
|
-
error: error instanceof Error ? error.message : String(error)
|
|
324
|
-
})
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
})
|
|
328
|
-
);
|
|
329
|
-
},
|
|
330
|
-
[mergedHandlers]
|
|
331
|
-
);
|
|
332
|
-
const continueWithResults = useCallback2(
|
|
333
|
-
async (tools, options) => {
|
|
334
|
-
if (!isPaused) {
|
|
335
|
-
throw new Error("No paused run to continue");
|
|
336
|
-
}
|
|
337
|
-
setIsExecuting(true);
|
|
283
|
+
const executeTools = useCallback2(async (tools) => {
|
|
284
|
+
return Promise.all(tools.map(async (tool) => {
|
|
285
|
+
const handler = mergedHandlers[tool.tool_name];
|
|
286
|
+
if (!handler)
|
|
287
|
+
return tool;
|
|
338
288
|
try {
|
|
339
|
-
await
|
|
289
|
+
const result = await handler(tool.tool_args);
|
|
290
|
+
const { resultData, uiComponent } = processToolResult(result, tool);
|
|
291
|
+
return {
|
|
292
|
+
...tool,
|
|
293
|
+
result: resultData,
|
|
294
|
+
ui_component: uiComponent
|
|
295
|
+
};
|
|
340
296
|
} catch (error) {
|
|
341
|
-
|
|
342
|
-
|
|
297
|
+
return {
|
|
298
|
+
...tool,
|
|
299
|
+
result: JSON.stringify({
|
|
300
|
+
error: error instanceof Error ? error.message : String(error)
|
|
301
|
+
})
|
|
302
|
+
};
|
|
343
303
|
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
)
|
|
304
|
+
}));
|
|
305
|
+
}, [mergedHandlers]);
|
|
306
|
+
const continueWithResults = useCallback2(async (tools, options) => {
|
|
307
|
+
if (!isPaused) {
|
|
308
|
+
throw new Error("No paused run to continue");
|
|
309
|
+
}
|
|
310
|
+
setIsExecuting(true);
|
|
311
|
+
try {
|
|
312
|
+
await client.continueRun(tools, options);
|
|
313
|
+
} catch (error) {
|
|
314
|
+
setIsExecuting(false);
|
|
315
|
+
throw error;
|
|
316
|
+
}
|
|
317
|
+
}, [client, isPaused]);
|
|
347
318
|
useEffect2(() => {
|
|
348
319
|
if (autoExecute && isPaused && !isExecuting && pendingTools.length > 0) {
|
|
349
320
|
executeAndContinue();
|
|
350
321
|
}
|
|
351
322
|
}, [autoExecute, isPaused, isExecuting, pendingTools.length, executeAndContinue]);
|
|
352
323
|
return {
|
|
353
|
-
/** Whether the run is currently paused awaiting tool execution */
|
|
354
324
|
isPaused,
|
|
355
|
-
/** Whether tools are currently being executed */
|
|
356
325
|
isExecuting,
|
|
357
|
-
/** Tools awaiting execution */
|
|
358
326
|
pendingTools,
|
|
359
|
-
/** Execute all pending tools and continue the run */
|
|
360
327
|
executeAndContinue,
|
|
361
|
-
/** Execute specific tools and return results without continuing */
|
|
362
328
|
executeTools,
|
|
363
|
-
/** Continue the run with manually provided tool results */
|
|
364
329
|
continueWithResults,
|
|
365
|
-
/** Error from tool execution, if any */
|
|
366
330
|
executionError
|
|
367
331
|
};
|
|
368
332
|
}
|
|
369
333
|
|
|
370
334
|
// src/components/GenerativeUIRenderer.tsx
|
|
371
|
-
import {
|
|
372
|
-
|
|
335
|
+
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
336
|
+
|
|
337
|
+
class UIErrorBoundary extends React3.Component {
|
|
373
338
|
constructor(props) {
|
|
374
339
|
super(props);
|
|
375
340
|
this.state = { hasError: false };
|
|
@@ -383,14 +348,23 @@ var UIErrorBoundary = class extends React3.Component {
|
|
|
383
348
|
}
|
|
384
349
|
render() {
|
|
385
350
|
if (this.state.hasError) {
|
|
386
|
-
return this.props.fallback || /* @__PURE__ */
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
351
|
+
return this.props.fallback || /* @__PURE__ */ jsxDEV3("div", {
|
|
352
|
+
className: "p-4 border border-red-300 rounded-md bg-red-50 text-red-800",
|
|
353
|
+
children: [
|
|
354
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
355
|
+
className: "font-semibold",
|
|
356
|
+
children: "Failed to render UI component"
|
|
357
|
+
}, undefined, false, undefined, this),
|
|
358
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
359
|
+
className: "text-sm mt-1",
|
|
360
|
+
children: this.state.error?.message || "Unknown error"
|
|
361
|
+
}, undefined, false, undefined, this)
|
|
362
|
+
]
|
|
363
|
+
}, undefined, true, undefined, this);
|
|
390
364
|
}
|
|
391
365
|
return this.props.children;
|
|
392
366
|
}
|
|
393
|
-
}
|
|
367
|
+
}
|
|
394
368
|
function GenerativeUIRenderer({
|
|
395
369
|
spec,
|
|
396
370
|
className,
|
|
@@ -402,78 +376,184 @@ function GenerativeUIRenderer({
|
|
|
402
376
|
if (customSpec.renderKey) {
|
|
403
377
|
const renderFn = getCustomRender(customSpec.renderKey);
|
|
404
378
|
if (renderFn) {
|
|
405
|
-
return /* @__PURE__ */
|
|
379
|
+
return /* @__PURE__ */ jsxDEV3(UIErrorBoundary, {
|
|
380
|
+
onError,
|
|
381
|
+
children: /* @__PURE__ */ jsxDEV3("div", {
|
|
382
|
+
className,
|
|
383
|
+
children: renderFn(customSpec.props || {})
|
|
384
|
+
}, undefined, false, undefined, this)
|
|
385
|
+
}, undefined, false, undefined, this);
|
|
406
386
|
}
|
|
407
387
|
}
|
|
408
|
-
return /* @__PURE__ */
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
388
|
+
return /* @__PURE__ */ jsxDEV3("div", {
|
|
389
|
+
className: `p-4 border border-yellow-300 rounded-md bg-yellow-50 text-yellow-800 ${className || ""}`,
|
|
390
|
+
children: [
|
|
391
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
392
|
+
className: "font-semibold",
|
|
393
|
+
children: "Custom component not available"
|
|
394
|
+
}, undefined, false, undefined, this),
|
|
395
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
396
|
+
className: "text-sm mt-1",
|
|
397
|
+
children: "The custom render function for this component is not available."
|
|
398
|
+
}, undefined, false, undefined, this)
|
|
399
|
+
]
|
|
400
|
+
}, undefined, true, undefined, this);
|
|
412
401
|
}
|
|
413
402
|
if (spec.type === "chart") {
|
|
414
403
|
const chartSpec = spec;
|
|
415
404
|
const chartType = `chart:${chartSpec.component}`;
|
|
416
405
|
if (registry.has(chartType)) {
|
|
417
406
|
const ChartRenderer = registry.get(chartType);
|
|
418
|
-
return /* @__PURE__ */
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
407
|
+
return /* @__PURE__ */ jsxDEV3(UIErrorBoundary, {
|
|
408
|
+
onError,
|
|
409
|
+
children: /* @__PURE__ */ jsxDEV3("div", {
|
|
410
|
+
className,
|
|
411
|
+
children: [
|
|
412
|
+
chartSpec.title && /* @__PURE__ */ jsxDEV3("h3", {
|
|
413
|
+
className: "font-semibold mb-2",
|
|
414
|
+
children: chartSpec.title
|
|
415
|
+
}, undefined, false, undefined, this),
|
|
416
|
+
chartSpec.description && /* @__PURE__ */ jsxDEV3("p", {
|
|
417
|
+
className: "text-sm text-gray-600 mb-4",
|
|
418
|
+
children: chartSpec.description
|
|
419
|
+
}, undefined, false, undefined, this),
|
|
420
|
+
/* @__PURE__ */ jsxDEV3(ChartRenderer, {
|
|
421
|
+
...chartSpec.props
|
|
422
|
+
}, undefined, false, undefined, this)
|
|
423
|
+
]
|
|
424
|
+
}, undefined, true, undefined, this)
|
|
425
|
+
}, undefined, false, undefined, this);
|
|
426
|
+
}
|
|
427
|
+
return /* @__PURE__ */ jsxDEV3("div", {
|
|
428
|
+
className: `p-4 border border-gray-300 rounded-md ${className || ""}`,
|
|
429
|
+
children: [
|
|
430
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
431
|
+
className: "font-semibold mb-2",
|
|
432
|
+
children: chartSpec.title || "Chart Data"
|
|
433
|
+
}, undefined, false, undefined, this),
|
|
434
|
+
chartSpec.description && /* @__PURE__ */ jsxDEV3("p", {
|
|
435
|
+
className: "text-sm text-gray-600 mb-2",
|
|
436
|
+
children: chartSpec.description
|
|
437
|
+
}, undefined, false, undefined, this),
|
|
438
|
+
/* @__PURE__ */ jsxDEV3("pre", {
|
|
439
|
+
className: "text-xs bg-gray-100 p-2 rounded overflow-auto",
|
|
440
|
+
children: JSON.stringify(chartSpec.props.data, null, 2)
|
|
441
|
+
}, undefined, false, undefined, this)
|
|
442
|
+
]
|
|
443
|
+
}, undefined, true, undefined, this);
|
|
429
444
|
}
|
|
430
445
|
if (spec.type === "card-grid") {
|
|
431
446
|
const cardGridSpec = spec;
|
|
432
447
|
if (registry.has("card-grid")) {
|
|
433
448
|
const CardGridRenderer = registry.get("card-grid");
|
|
434
|
-
return /* @__PURE__ */
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
449
|
+
return /* @__PURE__ */ jsxDEV3(UIErrorBoundary, {
|
|
450
|
+
onError,
|
|
451
|
+
children: /* @__PURE__ */ jsxDEV3("div", {
|
|
452
|
+
className,
|
|
453
|
+
children: [
|
|
454
|
+
cardGridSpec.title && /* @__PURE__ */ jsxDEV3("h3", {
|
|
455
|
+
className: "font-semibold mb-2",
|
|
456
|
+
children: cardGridSpec.title
|
|
457
|
+
}, undefined, false, undefined, this),
|
|
458
|
+
cardGridSpec.description && /* @__PURE__ */ jsxDEV3("p", {
|
|
459
|
+
className: "text-sm text-gray-600 mb-4",
|
|
460
|
+
children: cardGridSpec.description
|
|
461
|
+
}, undefined, false, undefined, this),
|
|
462
|
+
/* @__PURE__ */ jsxDEV3(CardGridRenderer, {
|
|
463
|
+
...cardGridSpec.props
|
|
464
|
+
}, undefined, false, undefined, this)
|
|
465
|
+
]
|
|
466
|
+
}, undefined, true, undefined, this)
|
|
467
|
+
}, undefined, false, undefined, this);
|
|
439
468
|
}
|
|
440
469
|
}
|
|
441
470
|
if (spec.type === "table") {
|
|
442
471
|
const tableSpec = spec;
|
|
443
472
|
if (registry.has("table")) {
|
|
444
473
|
const TableRenderer = registry.get("table");
|
|
445
|
-
return /* @__PURE__ */
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
474
|
+
return /* @__PURE__ */ jsxDEV3(UIErrorBoundary, {
|
|
475
|
+
onError,
|
|
476
|
+
children: /* @__PURE__ */ jsxDEV3("div", {
|
|
477
|
+
className,
|
|
478
|
+
children: [
|
|
479
|
+
tableSpec.title && /* @__PURE__ */ jsxDEV3("h3", {
|
|
480
|
+
className: "font-semibold mb-2",
|
|
481
|
+
children: tableSpec.title
|
|
482
|
+
}, undefined, false, undefined, this),
|
|
483
|
+
tableSpec.description && /* @__PURE__ */ jsxDEV3("p", {
|
|
484
|
+
className: "text-sm text-gray-600 mb-4",
|
|
485
|
+
children: tableSpec.description
|
|
486
|
+
}, undefined, false, undefined, this),
|
|
487
|
+
/* @__PURE__ */ jsxDEV3(TableRenderer, {
|
|
488
|
+
...tableSpec.props
|
|
489
|
+
}, undefined, false, undefined, this)
|
|
490
|
+
]
|
|
491
|
+
}, undefined, true, undefined, this)
|
|
492
|
+
}, undefined, false, undefined, this);
|
|
450
493
|
}
|
|
451
494
|
}
|
|
452
495
|
if (spec.type === "markdown") {
|
|
453
496
|
const markdownSpec = spec;
|
|
454
497
|
if (registry.has("markdown")) {
|
|
455
498
|
const MarkdownRenderer = registry.get("markdown");
|
|
456
|
-
return /* @__PURE__ */
|
|
499
|
+
return /* @__PURE__ */ jsxDEV3(UIErrorBoundary, {
|
|
500
|
+
onError,
|
|
501
|
+
children: /* @__PURE__ */ jsxDEV3("div", {
|
|
502
|
+
className,
|
|
503
|
+
children: /* @__PURE__ */ jsxDEV3(MarkdownRenderer, {
|
|
504
|
+
...markdownSpec.props
|
|
505
|
+
}, undefined, false, undefined, this)
|
|
506
|
+
}, undefined, false, undefined, this)
|
|
507
|
+
}, undefined, false, undefined, this);
|
|
457
508
|
}
|
|
458
|
-
return /* @__PURE__ */
|
|
509
|
+
return /* @__PURE__ */ jsxDEV3("div", {
|
|
510
|
+
className,
|
|
511
|
+
children: markdownSpec.props.content
|
|
512
|
+
}, undefined, false, undefined, this);
|
|
459
513
|
}
|
|
460
514
|
if (spec.type === "artifact") {
|
|
461
515
|
const artifactSpec = spec;
|
|
462
|
-
return /* @__PURE__ */
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
516
|
+
return /* @__PURE__ */ jsxDEV3(UIErrorBoundary, {
|
|
517
|
+
onError,
|
|
518
|
+
children: /* @__PURE__ */ jsxDEV3("div", {
|
|
519
|
+
className: `p-4 border rounded-md ${className || ""}`,
|
|
520
|
+
children: [
|
|
521
|
+
artifactSpec.title && /* @__PURE__ */ jsxDEV3("h3", {
|
|
522
|
+
className: "font-semibold mb-4",
|
|
523
|
+
children: artifactSpec.title
|
|
524
|
+
}, undefined, false, undefined, this),
|
|
525
|
+
artifactSpec.description && /* @__PURE__ */ jsxDEV3("p", {
|
|
526
|
+
className: "text-sm text-gray-600 mb-4",
|
|
527
|
+
children: artifactSpec.description
|
|
528
|
+
}, undefined, false, undefined, this),
|
|
529
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
530
|
+
className: "space-y-4",
|
|
531
|
+
children: artifactSpec.props.content?.map((childSpec, index) => /* @__PURE__ */ jsxDEV3(GenerativeUIRenderer, {
|
|
532
|
+
spec: childSpec,
|
|
533
|
+
onError
|
|
534
|
+
}, index, false, undefined, this))
|
|
535
|
+
}, undefined, false, undefined, this)
|
|
536
|
+
]
|
|
537
|
+
}, undefined, true, undefined, this)
|
|
538
|
+
}, undefined, false, undefined, this);
|
|
467
539
|
}
|
|
468
|
-
return /* @__PURE__ */
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
540
|
+
return /* @__PURE__ */ jsxDEV3("div", {
|
|
541
|
+
className: `p-4 border border-gray-300 rounded-md ${className || ""}`,
|
|
542
|
+
children: [
|
|
543
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
544
|
+
className: "font-semibold",
|
|
545
|
+
children: "Unsupported UI component"
|
|
546
|
+
}, undefined, false, undefined, this),
|
|
547
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
548
|
+
className: "text-sm text-gray-600 mt-1",
|
|
549
|
+
children: [
|
|
550
|
+
"Component type: ",
|
|
551
|
+
spec.type
|
|
552
|
+
]
|
|
553
|
+
}, undefined, true, undefined, this)
|
|
554
|
+
]
|
|
555
|
+
}, undefined, true, undefined, this);
|
|
475
556
|
}
|
|
476
|
-
|
|
477
557
|
// src/utils/ui-helpers.ts
|
|
478
558
|
function createBarChart(data, xKey, bars, options) {
|
|
479
559
|
return {
|
|
@@ -639,34 +719,17 @@ function createSmartChart(data, options) {
|
|
|
639
719
|
}
|
|
640
720
|
const firstItem = data[0];
|
|
641
721
|
const keys = Object.keys(firstItem);
|
|
642
|
-
const xKey = options?.xKey || keys.find(
|
|
643
|
-
(k) => ["name", "label", "category", "date", "time", "month", "year"].includes(k.toLowerCase())
|
|
644
|
-
) || keys[0];
|
|
722
|
+
const xKey = options?.xKey || keys.find((k) => ["name", "label", "category", "date", "time", "month", "year"].includes(k.toLowerCase())) || keys[0];
|
|
645
723
|
const numericKeys = keys.filter((k) => k !== xKey && typeof firstItem[k] === "number");
|
|
646
724
|
const yKeys = options?.yKeys || numericKeys;
|
|
647
725
|
if (options?.preferredType) {
|
|
648
726
|
switch (options.preferredType) {
|
|
649
727
|
case "bar":
|
|
650
|
-
return createBarChart(
|
|
651
|
-
data,
|
|
652
|
-
xKey,
|
|
653
|
-
yKeys.map((key) => ({ key })),
|
|
654
|
-
options
|
|
655
|
-
);
|
|
728
|
+
return createBarChart(data, xKey, yKeys.map((key) => ({ key })), options);
|
|
656
729
|
case "line":
|
|
657
|
-
return createLineChart(
|
|
658
|
-
data,
|
|
659
|
-
xKey,
|
|
660
|
-
yKeys.map((key) => ({ key })),
|
|
661
|
-
options
|
|
662
|
-
);
|
|
730
|
+
return createLineChart(data, xKey, yKeys.map((key) => ({ key })), options);
|
|
663
731
|
case "area":
|
|
664
|
-
return createAreaChart(
|
|
665
|
-
data,
|
|
666
|
-
xKey,
|
|
667
|
-
yKeys.map((key) => ({ key })),
|
|
668
|
-
options
|
|
669
|
-
);
|
|
732
|
+
return createAreaChart(data, xKey, yKeys.map((key) => ({ key })), options);
|
|
670
733
|
case "pie":
|
|
671
734
|
return createPieChart(data, yKeys[0], xKey, options);
|
|
672
735
|
}
|
|
@@ -675,19 +738,9 @@ function createSmartChart(data, options) {
|
|
|
675
738
|
return createPieChart(data, yKeys[0], xKey, options);
|
|
676
739
|
}
|
|
677
740
|
if (xKey.toLowerCase().includes("date") || xKey.toLowerCase().includes("time") || xKey.toLowerCase().includes("month") || xKey.toLowerCase().includes("year")) {
|
|
678
|
-
return createLineChart(
|
|
679
|
-
data,
|
|
680
|
-
xKey,
|
|
681
|
-
yKeys.map((key) => ({ key })),
|
|
682
|
-
options
|
|
683
|
-
);
|
|
741
|
+
return createLineChart(data, xKey, yKeys.map((key) => ({ key })), options);
|
|
684
742
|
}
|
|
685
|
-
return createBarChart(
|
|
686
|
-
data,
|
|
687
|
-
xKey,
|
|
688
|
-
yKeys.map((key) => ({ key })),
|
|
689
|
-
options
|
|
690
|
-
);
|
|
743
|
+
return createBarChart(data, xKey, yKeys.map((key) => ({ key })), options);
|
|
691
744
|
}
|
|
692
745
|
function createToolResult(data, ui) {
|
|
693
746
|
return { data, ui };
|
|
@@ -704,14 +757,12 @@ function resultWithCardGrid(cards, options) {
|
|
|
704
757
|
function resultWithTable(data, columns, options) {
|
|
705
758
|
return createToolResult(data, createTable(data, columns, options));
|
|
706
759
|
}
|
|
707
|
-
|
|
708
760
|
// src/hooks/useAgnoChat.ts
|
|
709
761
|
import { useState as useState3, useEffect as useEffect3, useCallback as useCallback3 } from "react";
|
|
710
762
|
function useAgnoChat() {
|
|
711
763
|
const client = useAgnoClient();
|
|
712
764
|
const [messages, setMessages] = useState3(client.getMessages());
|
|
713
765
|
const [state, setState] = useState3(client.getState());
|
|
714
|
-
const [error, setError] = useState3();
|
|
715
766
|
useEffect3(() => {
|
|
716
767
|
const handleMessageUpdate = (updatedMessages) => {
|
|
717
768
|
setMessages(updatedMessages);
|
|
@@ -722,9 +773,6 @@ function useAgnoChat() {
|
|
|
722
773
|
const handleMessageRefreshed = (updatedMessages) => {
|
|
723
774
|
setMessages(updatedMessages);
|
|
724
775
|
};
|
|
725
|
-
const handleMessageError = (errorMessage) => {
|
|
726
|
-
setError(errorMessage);
|
|
727
|
-
};
|
|
728
776
|
const handleStateChange = (newState) => {
|
|
729
777
|
setState(newState);
|
|
730
778
|
};
|
|
@@ -736,12 +784,10 @@ function useAgnoChat() {
|
|
|
736
784
|
}
|
|
737
785
|
}
|
|
738
786
|
};
|
|
739
|
-
const handleRunCancelled = () => {
|
|
740
|
-
};
|
|
787
|
+
const handleRunCancelled = () => {};
|
|
741
788
|
client.on("message:update", handleMessageUpdate);
|
|
742
789
|
client.on("message:complete", handleMessageComplete);
|
|
743
790
|
client.on("message:refreshed", handleMessageRefreshed);
|
|
744
|
-
client.on("message:error", handleMessageError);
|
|
745
791
|
client.on("state:change", handleStateChange);
|
|
746
792
|
client.on("ui:render", handleUIRender);
|
|
747
793
|
client.on("run:cancelled", handleRunCancelled);
|
|
@@ -751,38 +797,24 @@ function useAgnoChat() {
|
|
|
751
797
|
client.off("message:update", handleMessageUpdate);
|
|
752
798
|
client.off("message:complete", handleMessageComplete);
|
|
753
799
|
client.off("message:refreshed", handleMessageRefreshed);
|
|
754
|
-
client.off("message:error", handleMessageError);
|
|
755
800
|
client.off("state:change", handleStateChange);
|
|
756
801
|
client.off("ui:render", handleUIRender);
|
|
757
802
|
client.off("run:cancelled", handleRunCancelled);
|
|
758
803
|
};
|
|
759
804
|
}, [client]);
|
|
760
|
-
const sendMessage = useCallback3(
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
setError(errorMessage);
|
|
768
|
-
throw err;
|
|
769
|
-
}
|
|
770
|
-
},
|
|
771
|
-
[client]
|
|
772
|
-
);
|
|
805
|
+
const sendMessage = useCallback3(async (message, options) => {
|
|
806
|
+
try {
|
|
807
|
+
await client.sendMessage(message, options);
|
|
808
|
+
} catch (err) {
|
|
809
|
+
throw err;
|
|
810
|
+
}
|
|
811
|
+
}, [client]);
|
|
773
812
|
const clearMessages = useCallback3(() => {
|
|
774
813
|
client.clearMessages();
|
|
775
814
|
setMessages([]);
|
|
776
|
-
setError(void 0);
|
|
777
815
|
}, [client]);
|
|
778
816
|
const cancelRun = useCallback3(async () => {
|
|
779
|
-
|
|
780
|
-
await client.cancelRun();
|
|
781
|
-
} catch (err) {
|
|
782
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
783
|
-
setError(errorMessage);
|
|
784
|
-
throw err;
|
|
785
|
-
}
|
|
817
|
+
await client.cancelRun();
|
|
786
818
|
}, [client]);
|
|
787
819
|
return {
|
|
788
820
|
messages,
|
|
@@ -794,19 +826,16 @@ function useAgnoChat() {
|
|
|
794
826
|
isPaused: state.isPaused,
|
|
795
827
|
isCancelling: state.isCancelling,
|
|
796
828
|
currentRunId: state.currentRunId,
|
|
797
|
-
error,
|
|
829
|
+
error: state.errorMessage,
|
|
798
830
|
state
|
|
799
831
|
};
|
|
800
832
|
}
|
|
801
|
-
|
|
802
833
|
// src/hooks/useAgnoSession.ts
|
|
803
834
|
import { useState as useState4, useEffect as useEffect4, useCallback as useCallback4 } from "react";
|
|
804
835
|
function useAgnoSession() {
|
|
805
836
|
const client = useAgnoClient();
|
|
806
837
|
const [sessions, setSessions] = useState4([]);
|
|
807
|
-
const [currentSessionId, setCurrentSessionId] = useState4(
|
|
808
|
-
client.getConfig().sessionId
|
|
809
|
-
);
|
|
838
|
+
const [currentSessionId, setCurrentSessionId] = useState4(client.getConfig().sessionId);
|
|
810
839
|
const [isLoading, setIsLoading] = useState4(false);
|
|
811
840
|
const [error, setError] = useState4();
|
|
812
841
|
useEffect4(() => {
|
|
@@ -833,27 +862,24 @@ function useAgnoSession() {
|
|
|
833
862
|
client.off("state:change", handleStateChange);
|
|
834
863
|
};
|
|
835
864
|
}, [client]);
|
|
836
|
-
const loadSession = useCallback4(
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
},
|
|
852
|
-
[client]
|
|
853
|
-
);
|
|
865
|
+
const loadSession = useCallback4(async (sessionId, options) => {
|
|
866
|
+
setIsLoading(true);
|
|
867
|
+
setError(undefined);
|
|
868
|
+
try {
|
|
869
|
+
const messages = await client.loadSession(sessionId, options);
|
|
870
|
+
setCurrentSessionId(sessionId);
|
|
871
|
+
return messages;
|
|
872
|
+
} catch (err) {
|
|
873
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
874
|
+
setError(errorMessage);
|
|
875
|
+
throw err;
|
|
876
|
+
} finally {
|
|
877
|
+
setIsLoading(false);
|
|
878
|
+
}
|
|
879
|
+
}, [client]);
|
|
854
880
|
const fetchSessions = useCallback4(async (options) => {
|
|
855
881
|
setIsLoading(true);
|
|
856
|
-
setError(
|
|
882
|
+
setError(undefined);
|
|
857
883
|
try {
|
|
858
884
|
const fetchedSessions = await client.fetchSessions(options);
|
|
859
885
|
setSessions(fetchedSessions);
|
|
@@ -866,119 +892,98 @@ function useAgnoSession() {
|
|
|
866
892
|
setIsLoading(false);
|
|
867
893
|
}
|
|
868
894
|
}, [client]);
|
|
869
|
-
const getSessionById = useCallback4(
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
setIsLoading(false);
|
|
962
|
-
}
|
|
963
|
-
},
|
|
964
|
-
[client]
|
|
965
|
-
);
|
|
966
|
-
const deleteMultipleSessions = useCallback4(
|
|
967
|
-
async (sessionIds, options) => {
|
|
968
|
-
setIsLoading(true);
|
|
969
|
-
setError(void 0);
|
|
970
|
-
try {
|
|
971
|
-
await client.deleteMultipleSessions(sessionIds, options);
|
|
972
|
-
} catch (err) {
|
|
973
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
974
|
-
setError(errorMessage);
|
|
975
|
-
throw err;
|
|
976
|
-
} finally {
|
|
977
|
-
setIsLoading(false);
|
|
978
|
-
}
|
|
979
|
-
},
|
|
980
|
-
[client]
|
|
981
|
-
);
|
|
895
|
+
const getSessionById = useCallback4(async (sessionId, options) => {
|
|
896
|
+
setIsLoading(true);
|
|
897
|
+
setError(undefined);
|
|
898
|
+
try {
|
|
899
|
+
return await client.getSessionById(sessionId, options);
|
|
900
|
+
} catch (err) {
|
|
901
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
902
|
+
setError(errorMessage);
|
|
903
|
+
throw err;
|
|
904
|
+
} finally {
|
|
905
|
+
setIsLoading(false);
|
|
906
|
+
}
|
|
907
|
+
}, [client]);
|
|
908
|
+
const getRunById = useCallback4(async (sessionId, runId, options) => {
|
|
909
|
+
setIsLoading(true);
|
|
910
|
+
setError(undefined);
|
|
911
|
+
try {
|
|
912
|
+
return await client.getRunById(sessionId, runId, options);
|
|
913
|
+
} catch (err) {
|
|
914
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
915
|
+
setError(errorMessage);
|
|
916
|
+
throw err;
|
|
917
|
+
} finally {
|
|
918
|
+
setIsLoading(false);
|
|
919
|
+
}
|
|
920
|
+
}, [client]);
|
|
921
|
+
const createSession = useCallback4(async (request, options) => {
|
|
922
|
+
setIsLoading(true);
|
|
923
|
+
setError(undefined);
|
|
924
|
+
try {
|
|
925
|
+
const session = await client.createSession(request, options);
|
|
926
|
+
return session;
|
|
927
|
+
} catch (err) {
|
|
928
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
929
|
+
setError(errorMessage);
|
|
930
|
+
throw err;
|
|
931
|
+
} finally {
|
|
932
|
+
setIsLoading(false);
|
|
933
|
+
}
|
|
934
|
+
}, [client]);
|
|
935
|
+
const updateSession = useCallback4(async (sessionId, request, options) => {
|
|
936
|
+
setIsLoading(true);
|
|
937
|
+
setError(undefined);
|
|
938
|
+
try {
|
|
939
|
+
return await client.updateSession(sessionId, request, options);
|
|
940
|
+
} catch (err) {
|
|
941
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
942
|
+
setError(errorMessage);
|
|
943
|
+
throw err;
|
|
944
|
+
} finally {
|
|
945
|
+
setIsLoading(false);
|
|
946
|
+
}
|
|
947
|
+
}, [client]);
|
|
948
|
+
const renameSession = useCallback4(async (sessionId, newName, options) => {
|
|
949
|
+
setIsLoading(true);
|
|
950
|
+
setError(undefined);
|
|
951
|
+
try {
|
|
952
|
+
return await client.renameSession(sessionId, newName, options);
|
|
953
|
+
} catch (err) {
|
|
954
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
955
|
+
setError(errorMessage);
|
|
956
|
+
throw err;
|
|
957
|
+
} finally {
|
|
958
|
+
setIsLoading(false);
|
|
959
|
+
}
|
|
960
|
+
}, [client]);
|
|
961
|
+
const deleteSession = useCallback4(async (sessionId, options) => {
|
|
962
|
+
setIsLoading(true);
|
|
963
|
+
setError(undefined);
|
|
964
|
+
try {
|
|
965
|
+
await client.deleteSession(sessionId, options);
|
|
966
|
+
} catch (err) {
|
|
967
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
968
|
+
setError(errorMessage);
|
|
969
|
+
throw err;
|
|
970
|
+
} finally {
|
|
971
|
+
setIsLoading(false);
|
|
972
|
+
}
|
|
973
|
+
}, [client]);
|
|
974
|
+
const deleteMultipleSessions = useCallback4(async (sessionIds, options) => {
|
|
975
|
+
setIsLoading(true);
|
|
976
|
+
setError(undefined);
|
|
977
|
+
try {
|
|
978
|
+
await client.deleteMultipleSessions(sessionIds, options);
|
|
979
|
+
} catch (err) {
|
|
980
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
981
|
+
setError(errorMessage);
|
|
982
|
+
throw err;
|
|
983
|
+
} finally {
|
|
984
|
+
setIsLoading(false);
|
|
985
|
+
}
|
|
986
|
+
}, [client]);
|
|
982
987
|
return {
|
|
983
988
|
sessions,
|
|
984
989
|
currentSessionId,
|
|
@@ -995,7 +1000,6 @@ function useAgnoSession() {
|
|
|
995
1000
|
error
|
|
996
1001
|
};
|
|
997
1002
|
}
|
|
998
|
-
|
|
999
1003
|
// src/hooks/useAgnoActions.ts
|
|
1000
1004
|
import { useState as useState5, useCallback as useCallback5 } from "react";
|
|
1001
1005
|
function useAgnoActions() {
|
|
@@ -1004,7 +1008,7 @@ function useAgnoActions() {
|
|
|
1004
1008
|
const [error, setError] = useState5();
|
|
1005
1009
|
const initialize = useCallback5(async (options) => {
|
|
1006
1010
|
setIsInitializing(true);
|
|
1007
|
-
setError(
|
|
1011
|
+
setError(undefined);
|
|
1008
1012
|
try {
|
|
1009
1013
|
const result = await client.initialize(options);
|
|
1010
1014
|
return result;
|
|
@@ -1017,7 +1021,7 @@ function useAgnoActions() {
|
|
|
1017
1021
|
}
|
|
1018
1022
|
}, [client]);
|
|
1019
1023
|
const checkStatus = useCallback5(async (options) => {
|
|
1020
|
-
setError(
|
|
1024
|
+
setError(undefined);
|
|
1021
1025
|
try {
|
|
1022
1026
|
return await client.checkStatus(options);
|
|
1023
1027
|
} catch (err) {
|
|
@@ -1027,7 +1031,7 @@ function useAgnoActions() {
|
|
|
1027
1031
|
}
|
|
1028
1032
|
}, [client]);
|
|
1029
1033
|
const fetchAgents = useCallback5(async (options) => {
|
|
1030
|
-
setError(
|
|
1034
|
+
setError(undefined);
|
|
1031
1035
|
try {
|
|
1032
1036
|
return await client.fetchAgents(options);
|
|
1033
1037
|
} catch (err) {
|
|
@@ -1037,7 +1041,7 @@ function useAgnoActions() {
|
|
|
1037
1041
|
}
|
|
1038
1042
|
}, [client]);
|
|
1039
1043
|
const fetchTeams = useCallback5(async (options) => {
|
|
1040
|
-
setError(
|
|
1044
|
+
setError(undefined);
|
|
1041
1045
|
try {
|
|
1042
1046
|
return await client.fetchTeams(options);
|
|
1043
1047
|
} catch (err) {
|
|
@@ -1046,12 +1050,9 @@ function useAgnoActions() {
|
|
|
1046
1050
|
throw err;
|
|
1047
1051
|
}
|
|
1048
1052
|
}, [client]);
|
|
1049
|
-
const updateConfig = useCallback5(
|
|
1050
|
-
(updates)
|
|
1051
|
-
|
|
1052
|
-
},
|
|
1053
|
-
[client]
|
|
1054
|
-
);
|
|
1053
|
+
const updateConfig = useCallback5((updates) => {
|
|
1054
|
+
client.updateConfig(updates);
|
|
1055
|
+
}, [client]);
|
|
1055
1056
|
return {
|
|
1056
1057
|
initialize,
|
|
1057
1058
|
checkStatus,
|
|
@@ -1062,7 +1063,6 @@ function useAgnoActions() {
|
|
|
1062
1063
|
error
|
|
1063
1064
|
};
|
|
1064
1065
|
}
|
|
1065
|
-
|
|
1066
1066
|
// src/hooks/useAgnoCustomEvents.ts
|
|
1067
1067
|
import { useState as useState6, useEffect as useEffect5, useCallback as useCallback6, useRef } from "react";
|
|
1068
1068
|
function useAgnoCustomEvents(handler) {
|
|
@@ -1085,7 +1085,6 @@ function useAgnoCustomEvents(handler) {
|
|
|
1085
1085
|
}, []);
|
|
1086
1086
|
return { events, clearEvents };
|
|
1087
1087
|
}
|
|
1088
|
-
|
|
1089
1088
|
// src/hooks/useAgnoMemory.ts
|
|
1090
1089
|
import { useState as useState7, useEffect as useEffect6, useCallback as useCallback7 } from "react";
|
|
1091
1090
|
function useAgnoMemory() {
|
|
@@ -1099,9 +1098,7 @@ function useAgnoMemory() {
|
|
|
1099
1098
|
setMemories((prev) => [memory, ...prev]);
|
|
1100
1099
|
};
|
|
1101
1100
|
const handleMemoryUpdated = (memory) => {
|
|
1102
|
-
setMemories(
|
|
1103
|
-
(prev) => prev.map((m) => m.memory_id === memory.memory_id ? memory : m)
|
|
1104
|
-
);
|
|
1101
|
+
setMemories((prev) => prev.map((m) => m.memory_id === memory.memory_id ? memory : m));
|
|
1105
1102
|
};
|
|
1106
1103
|
const handleMemoryDeleted = ({ memoryId }) => {
|
|
1107
1104
|
setMemories((prev) => prev.filter((m) => m.memory_id !== memoryId));
|
|
@@ -1131,138 +1128,114 @@ function useAgnoMemory() {
|
|
|
1131
1128
|
client.off("state:change", handleStateChange);
|
|
1132
1129
|
};
|
|
1133
1130
|
}, [client]);
|
|
1134
|
-
const fetchMemories = useCallback7(
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
setError(
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
setError(errorMessage);
|
|
1243
|
-
throw err;
|
|
1244
|
-
} finally {
|
|
1245
|
-
setIsLoading(false);
|
|
1246
|
-
}
|
|
1247
|
-
},
|
|
1248
|
-
[client]
|
|
1249
|
-
);
|
|
1250
|
-
const deleteMultipleMemories = useCallback7(
|
|
1251
|
-
async (memoryIds, options) => {
|
|
1252
|
-
setIsLoading(true);
|
|
1253
|
-
setError(void 0);
|
|
1254
|
-
try {
|
|
1255
|
-
await client.deleteMultipleMemories(memoryIds, options);
|
|
1256
|
-
} catch (err) {
|
|
1257
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1258
|
-
setError(errorMessage);
|
|
1259
|
-
throw err;
|
|
1260
|
-
} finally {
|
|
1261
|
-
setIsLoading(false);
|
|
1262
|
-
}
|
|
1263
|
-
},
|
|
1264
|
-
[client]
|
|
1265
|
-
);
|
|
1131
|
+
const fetchMemories = useCallback7(async (queryParams, options) => {
|
|
1132
|
+
setIsLoading(true);
|
|
1133
|
+
setError(undefined);
|
|
1134
|
+
try {
|
|
1135
|
+
const response = await client.fetchMemories(queryParams, options);
|
|
1136
|
+
setMemories(response.data);
|
|
1137
|
+
return response;
|
|
1138
|
+
} catch (err) {
|
|
1139
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1140
|
+
setError(errorMessage);
|
|
1141
|
+
throw err;
|
|
1142
|
+
} finally {
|
|
1143
|
+
setIsLoading(false);
|
|
1144
|
+
}
|
|
1145
|
+
}, [client]);
|
|
1146
|
+
const getMemoryById = useCallback7(async (memoryId, options) => {
|
|
1147
|
+
setIsLoading(true);
|
|
1148
|
+
setError(undefined);
|
|
1149
|
+
try {
|
|
1150
|
+
return await client.getMemoryById(memoryId, options);
|
|
1151
|
+
} catch (err) {
|
|
1152
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1153
|
+
setError(errorMessage);
|
|
1154
|
+
throw err;
|
|
1155
|
+
} finally {
|
|
1156
|
+
setIsLoading(false);
|
|
1157
|
+
}
|
|
1158
|
+
}, [client]);
|
|
1159
|
+
const getMemoryTopics = useCallback7(async (options) => {
|
|
1160
|
+
setIsLoading(true);
|
|
1161
|
+
setError(undefined);
|
|
1162
|
+
try {
|
|
1163
|
+
const result = await client.getMemoryTopics(options);
|
|
1164
|
+
setTopics(result);
|
|
1165
|
+
return result;
|
|
1166
|
+
} catch (err) {
|
|
1167
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1168
|
+
setError(errorMessage);
|
|
1169
|
+
throw err;
|
|
1170
|
+
} finally {
|
|
1171
|
+
setIsLoading(false);
|
|
1172
|
+
}
|
|
1173
|
+
}, [client]);
|
|
1174
|
+
const getUserMemoryStats = useCallback7(async (queryParams, options) => {
|
|
1175
|
+
setIsLoading(true);
|
|
1176
|
+
setError(undefined);
|
|
1177
|
+
try {
|
|
1178
|
+
return await client.getUserMemoryStats(queryParams, options);
|
|
1179
|
+
} catch (err) {
|
|
1180
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1181
|
+
setError(errorMessage);
|
|
1182
|
+
throw err;
|
|
1183
|
+
} finally {
|
|
1184
|
+
setIsLoading(false);
|
|
1185
|
+
}
|
|
1186
|
+
}, [client]);
|
|
1187
|
+
const createMemory = useCallback7(async (request, options) => {
|
|
1188
|
+
setIsLoading(true);
|
|
1189
|
+
setError(undefined);
|
|
1190
|
+
try {
|
|
1191
|
+
return await client.createMemory(request, options);
|
|
1192
|
+
} catch (err) {
|
|
1193
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1194
|
+
setError(errorMessage);
|
|
1195
|
+
throw err;
|
|
1196
|
+
} finally {
|
|
1197
|
+
setIsLoading(false);
|
|
1198
|
+
}
|
|
1199
|
+
}, [client]);
|
|
1200
|
+
const updateMemory = useCallback7(async (memoryId, request, options) => {
|
|
1201
|
+
setIsLoading(true);
|
|
1202
|
+
setError(undefined);
|
|
1203
|
+
try {
|
|
1204
|
+
return await client.updateMemory(memoryId, request, options);
|
|
1205
|
+
} catch (err) {
|
|
1206
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1207
|
+
setError(errorMessage);
|
|
1208
|
+
throw err;
|
|
1209
|
+
} finally {
|
|
1210
|
+
setIsLoading(false);
|
|
1211
|
+
}
|
|
1212
|
+
}, [client]);
|
|
1213
|
+
const deleteMemory = useCallback7(async (memoryId, options) => {
|
|
1214
|
+
setIsLoading(true);
|
|
1215
|
+
setError(undefined);
|
|
1216
|
+
try {
|
|
1217
|
+
await client.deleteMemory(memoryId, options);
|
|
1218
|
+
} catch (err) {
|
|
1219
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1220
|
+
setError(errorMessage);
|
|
1221
|
+
throw err;
|
|
1222
|
+
} finally {
|
|
1223
|
+
setIsLoading(false);
|
|
1224
|
+
}
|
|
1225
|
+
}, [client]);
|
|
1226
|
+
const deleteMultipleMemories = useCallback7(async (memoryIds, options) => {
|
|
1227
|
+
setIsLoading(true);
|
|
1228
|
+
setError(undefined);
|
|
1229
|
+
try {
|
|
1230
|
+
await client.deleteMultipleMemories(memoryIds, options);
|
|
1231
|
+
} catch (err) {
|
|
1232
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1233
|
+
setError(errorMessage);
|
|
1234
|
+
throw err;
|
|
1235
|
+
} finally {
|
|
1236
|
+
setIsLoading(false);
|
|
1237
|
+
}
|
|
1238
|
+
}, [client]);
|
|
1266
1239
|
return {
|
|
1267
1240
|
memories,
|
|
1268
1241
|
topics,
|
|
@@ -1278,7 +1251,6 @@ function useAgnoMemory() {
|
|
|
1278
1251
|
deleteMultipleMemories
|
|
1279
1252
|
};
|
|
1280
1253
|
}
|
|
1281
|
-
|
|
1282
1254
|
// src/hooks/useAgnoKnowledge.ts
|
|
1283
1255
|
import { useState as useState8, useCallback as useCallback8 } from "react";
|
|
1284
1256
|
function useAgnoKnowledge() {
|
|
@@ -1287,172 +1259,139 @@ function useAgnoKnowledge() {
|
|
|
1287
1259
|
const [error, setError] = useState8();
|
|
1288
1260
|
const [config, setConfig] = useState8();
|
|
1289
1261
|
const [content, setContent] = useState8([]);
|
|
1290
|
-
const getConfig = useCallback8(
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
);
|
|
1374
|
-
const
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
try {
|
|
1419
|
-
await client.deleteAllKnowledgeContent(options);
|
|
1420
|
-
setContent([]);
|
|
1421
|
-
} catch (err) {
|
|
1422
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1423
|
-
setError(errorMessage);
|
|
1424
|
-
throw err;
|
|
1425
|
-
} finally {
|
|
1426
|
-
setIsLoading(false);
|
|
1427
|
-
}
|
|
1428
|
-
},
|
|
1429
|
-
[client]
|
|
1430
|
-
);
|
|
1431
|
-
const deleteContent = useCallback8(
|
|
1432
|
-
async (contentId, options) => {
|
|
1433
|
-
setIsLoading(true);
|
|
1434
|
-
setError(void 0);
|
|
1435
|
-
try {
|
|
1436
|
-
const result = await client.deleteKnowledgeContent(contentId, options);
|
|
1437
|
-
setContent((prev) => prev.filter((c) => c.id !== contentId));
|
|
1438
|
-
return result;
|
|
1439
|
-
} catch (err) {
|
|
1440
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1441
|
-
setError(errorMessage);
|
|
1442
|
-
throw err;
|
|
1443
|
-
} finally {
|
|
1444
|
-
setIsLoading(false);
|
|
1445
|
-
}
|
|
1446
|
-
},
|
|
1447
|
-
[client]
|
|
1448
|
-
);
|
|
1262
|
+
const getConfig = useCallback8(async (options) => {
|
|
1263
|
+
setIsLoading(true);
|
|
1264
|
+
setError(undefined);
|
|
1265
|
+
try {
|
|
1266
|
+
const result = await client.getKnowledgeConfig(options);
|
|
1267
|
+
setConfig(result);
|
|
1268
|
+
return result;
|
|
1269
|
+
} catch (err) {
|
|
1270
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1271
|
+
setError(errorMessage);
|
|
1272
|
+
throw err;
|
|
1273
|
+
} finally {
|
|
1274
|
+
setIsLoading(false);
|
|
1275
|
+
}
|
|
1276
|
+
}, [client]);
|
|
1277
|
+
const listContent = useCallback8(async (listOptions, options) => {
|
|
1278
|
+
setIsLoading(true);
|
|
1279
|
+
setError(undefined);
|
|
1280
|
+
try {
|
|
1281
|
+
const result = await client.listKnowledgeContent(listOptions, options);
|
|
1282
|
+
setContent(result.data);
|
|
1283
|
+
return result;
|
|
1284
|
+
} catch (err) {
|
|
1285
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1286
|
+
setError(errorMessage);
|
|
1287
|
+
throw err;
|
|
1288
|
+
} finally {
|
|
1289
|
+
setIsLoading(false);
|
|
1290
|
+
}
|
|
1291
|
+
}, [client]);
|
|
1292
|
+
const getContent = useCallback8(async (contentId, options) => {
|
|
1293
|
+
setIsLoading(true);
|
|
1294
|
+
setError(undefined);
|
|
1295
|
+
try {
|
|
1296
|
+
return await client.getKnowledgeContent(contentId, options);
|
|
1297
|
+
} catch (err) {
|
|
1298
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1299
|
+
setError(errorMessage);
|
|
1300
|
+
throw err;
|
|
1301
|
+
} finally {
|
|
1302
|
+
setIsLoading(false);
|
|
1303
|
+
}
|
|
1304
|
+
}, [client]);
|
|
1305
|
+
const getContentStatus = useCallback8(async (contentId, options) => {
|
|
1306
|
+
setIsLoading(true);
|
|
1307
|
+
setError(undefined);
|
|
1308
|
+
try {
|
|
1309
|
+
return await client.getKnowledgeContentStatus(contentId, options);
|
|
1310
|
+
} catch (err) {
|
|
1311
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1312
|
+
setError(errorMessage);
|
|
1313
|
+
throw err;
|
|
1314
|
+
} finally {
|
|
1315
|
+
setIsLoading(false);
|
|
1316
|
+
}
|
|
1317
|
+
}, [client]);
|
|
1318
|
+
const search = useCallback8(async (request, options) => {
|
|
1319
|
+
setIsLoading(true);
|
|
1320
|
+
setError(undefined);
|
|
1321
|
+
try {
|
|
1322
|
+
return await client.searchKnowledge(request, options);
|
|
1323
|
+
} catch (err) {
|
|
1324
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1325
|
+
setError(errorMessage);
|
|
1326
|
+
throw err;
|
|
1327
|
+
} finally {
|
|
1328
|
+
setIsLoading(false);
|
|
1329
|
+
}
|
|
1330
|
+
}, [client]);
|
|
1331
|
+
const uploadContent = useCallback8(async (data, options) => {
|
|
1332
|
+
setIsLoading(true);
|
|
1333
|
+
setError(undefined);
|
|
1334
|
+
try {
|
|
1335
|
+
const result = await client.uploadKnowledgeContent(data, options);
|
|
1336
|
+
setContent((prev) => [result, ...prev]);
|
|
1337
|
+
return result;
|
|
1338
|
+
} catch (err) {
|
|
1339
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1340
|
+
setError(errorMessage);
|
|
1341
|
+
throw err;
|
|
1342
|
+
} finally {
|
|
1343
|
+
setIsLoading(false);
|
|
1344
|
+
}
|
|
1345
|
+
}, [client]);
|
|
1346
|
+
const updateContent = useCallback8(async (contentId, request, options) => {
|
|
1347
|
+
setIsLoading(true);
|
|
1348
|
+
setError(undefined);
|
|
1349
|
+
try {
|
|
1350
|
+
const result = await client.updateKnowledgeContent(contentId, request, options);
|
|
1351
|
+
setContent((prev) => prev.map((c) => c.id === contentId ? result : c));
|
|
1352
|
+
return result;
|
|
1353
|
+
} catch (err) {
|
|
1354
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1355
|
+
setError(errorMessage);
|
|
1356
|
+
throw err;
|
|
1357
|
+
} finally {
|
|
1358
|
+
setIsLoading(false);
|
|
1359
|
+
}
|
|
1360
|
+
}, [client]);
|
|
1361
|
+
const deleteAllContent = useCallback8(async (options) => {
|
|
1362
|
+
setIsLoading(true);
|
|
1363
|
+
setError(undefined);
|
|
1364
|
+
try {
|
|
1365
|
+
await client.deleteAllKnowledgeContent(options);
|
|
1366
|
+
setContent([]);
|
|
1367
|
+
} catch (err) {
|
|
1368
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1369
|
+
setError(errorMessage);
|
|
1370
|
+
throw err;
|
|
1371
|
+
} finally {
|
|
1372
|
+
setIsLoading(false);
|
|
1373
|
+
}
|
|
1374
|
+
}, [client]);
|
|
1375
|
+
const deleteContent = useCallback8(async (contentId, options) => {
|
|
1376
|
+
setIsLoading(true);
|
|
1377
|
+
setError(undefined);
|
|
1378
|
+
try {
|
|
1379
|
+
const result = await client.deleteKnowledgeContent(contentId, options);
|
|
1380
|
+
setContent((prev) => prev.filter((c) => c.id !== contentId));
|
|
1381
|
+
return result;
|
|
1382
|
+
} catch (err) {
|
|
1383
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1384
|
+
setError(errorMessage);
|
|
1385
|
+
throw err;
|
|
1386
|
+
} finally {
|
|
1387
|
+
setIsLoading(false);
|
|
1388
|
+
}
|
|
1389
|
+
}, [client]);
|
|
1449
1390
|
return {
|
|
1450
|
-
// State
|
|
1451
1391
|
config,
|
|
1452
1392
|
content,
|
|
1453
1393
|
isLoading,
|
|
1454
1394
|
error,
|
|
1455
|
-
// Methods
|
|
1456
1395
|
getConfig,
|
|
1457
1396
|
listContent,
|
|
1458
1397
|
getContent,
|
|
@@ -1464,7 +1403,6 @@ function useAgnoKnowledge() {
|
|
|
1464
1403
|
deleteContent
|
|
1465
1404
|
};
|
|
1466
1405
|
}
|
|
1467
|
-
|
|
1468
1406
|
// src/hooks/useAgnoMetrics.ts
|
|
1469
1407
|
import { useState as useState9, useCallback as useCallback9 } from "react";
|
|
1470
1408
|
function useAgnoMetrics() {
|
|
@@ -1473,59 +1411,49 @@ function useAgnoMetrics() {
|
|
|
1473
1411
|
const [isRefreshing, setIsRefreshing] = useState9(false);
|
|
1474
1412
|
const [error, setError] = useState9();
|
|
1475
1413
|
const [metrics, setMetrics] = useState9();
|
|
1476
|
-
const fetchMetrics = useCallback9(
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
} finally {
|
|
1506
|
-
setIsRefreshing(false);
|
|
1507
|
-
}
|
|
1508
|
-
},
|
|
1509
|
-
[client]
|
|
1510
|
-
);
|
|
1414
|
+
const fetchMetrics = useCallback9(async (options) => {
|
|
1415
|
+
setIsLoading(true);
|
|
1416
|
+
setError(undefined);
|
|
1417
|
+
try {
|
|
1418
|
+
const result = await client.fetchMetrics(options);
|
|
1419
|
+
setMetrics(result);
|
|
1420
|
+
return result;
|
|
1421
|
+
} catch (err) {
|
|
1422
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1423
|
+
setError(errorMessage);
|
|
1424
|
+
throw err;
|
|
1425
|
+
} finally {
|
|
1426
|
+
setIsLoading(false);
|
|
1427
|
+
}
|
|
1428
|
+
}, [client]);
|
|
1429
|
+
const refreshMetrics = useCallback9(async (options) => {
|
|
1430
|
+
setIsRefreshing(true);
|
|
1431
|
+
setError(undefined);
|
|
1432
|
+
try {
|
|
1433
|
+
const result = await client.refreshMetrics(options);
|
|
1434
|
+
return result;
|
|
1435
|
+
} catch (err) {
|
|
1436
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1437
|
+
setError(errorMessage);
|
|
1438
|
+
throw err;
|
|
1439
|
+
} finally {
|
|
1440
|
+
setIsRefreshing(false);
|
|
1441
|
+
}
|
|
1442
|
+
}, [client]);
|
|
1511
1443
|
const clearMetrics = useCallback9(() => {
|
|
1512
|
-
setMetrics(
|
|
1513
|
-
setError(
|
|
1444
|
+
setMetrics(undefined);
|
|
1445
|
+
setError(undefined);
|
|
1514
1446
|
}, []);
|
|
1515
1447
|
return {
|
|
1516
|
-
// Data
|
|
1517
1448
|
metrics,
|
|
1518
|
-
// Actions
|
|
1519
1449
|
fetchMetrics,
|
|
1520
1450
|
refreshMetrics,
|
|
1521
1451
|
clearMetrics,
|
|
1522
|
-
// State
|
|
1523
1452
|
isLoading,
|
|
1524
1453
|
isRefreshing,
|
|
1525
1454
|
error
|
|
1526
1455
|
};
|
|
1527
1456
|
}
|
|
1528
|
-
|
|
1529
1457
|
// src/hooks/useAgnoEvals.ts
|
|
1530
1458
|
import { useState as useState10, useCallback as useCallback10 } from "react";
|
|
1531
1459
|
function useAgnoEvals() {
|
|
@@ -1534,110 +1462,88 @@ function useAgnoEvals() {
|
|
|
1534
1462
|
const [pagination, setPagination] = useState10();
|
|
1535
1463
|
const [isLoading, setIsLoading] = useState10(false);
|
|
1536
1464
|
const [error, setError] = useState10();
|
|
1537
|
-
const listEvalRuns = useCallback10(
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
setError(
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
}
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
try {
|
|
1615
|
-
await client.deleteEvalRuns(evalRunIds, options);
|
|
1616
|
-
const deletedSet = new Set(evalRunIds);
|
|
1617
|
-
setEvalRuns((prev) => prev.filter((evalRun) => !deletedSet.has(evalRun.id)));
|
|
1618
|
-
} catch (err) {
|
|
1619
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1620
|
-
setError(errorMessage);
|
|
1621
|
-
throw err;
|
|
1622
|
-
} finally {
|
|
1623
|
-
setIsLoading(false);
|
|
1624
|
-
}
|
|
1625
|
-
},
|
|
1626
|
-
[client]
|
|
1627
|
-
);
|
|
1628
|
-
const renameEvalRun = useCallback10(
|
|
1629
|
-
async (evalRunId, newName, options) => {
|
|
1630
|
-
return updateEvalRun(evalRunId, { name: newName }, options);
|
|
1631
|
-
},
|
|
1632
|
-
[updateEvalRun]
|
|
1633
|
-
);
|
|
1465
|
+
const listEvalRuns = useCallback10(async (listParams = {}, options) => {
|
|
1466
|
+
setIsLoading(true);
|
|
1467
|
+
setError(undefined);
|
|
1468
|
+
try {
|
|
1469
|
+
const response = await client.listEvalRuns(listParams, options);
|
|
1470
|
+
setEvalRuns(response.data);
|
|
1471
|
+
setPagination(response.meta);
|
|
1472
|
+
return response;
|
|
1473
|
+
} catch (err) {
|
|
1474
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1475
|
+
setError(errorMessage);
|
|
1476
|
+
throw err;
|
|
1477
|
+
} finally {
|
|
1478
|
+
setIsLoading(false);
|
|
1479
|
+
}
|
|
1480
|
+
}, [client]);
|
|
1481
|
+
const getEvalRun = useCallback10(async (evalRunId, options) => {
|
|
1482
|
+
setIsLoading(true);
|
|
1483
|
+
setError(undefined);
|
|
1484
|
+
try {
|
|
1485
|
+
return await client.getEvalRun(evalRunId, options);
|
|
1486
|
+
} catch (err) {
|
|
1487
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1488
|
+
setError(errorMessage);
|
|
1489
|
+
throw err;
|
|
1490
|
+
} finally {
|
|
1491
|
+
setIsLoading(false);
|
|
1492
|
+
}
|
|
1493
|
+
}, [client]);
|
|
1494
|
+
const executeEval = useCallback10(async (request, options) => {
|
|
1495
|
+
setIsLoading(true);
|
|
1496
|
+
setError(undefined);
|
|
1497
|
+
try {
|
|
1498
|
+
const result = await client.executeEval(request, options);
|
|
1499
|
+
setEvalRuns((prev) => [result, ...prev]);
|
|
1500
|
+
return result;
|
|
1501
|
+
} catch (err) {
|
|
1502
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1503
|
+
setError(errorMessage);
|
|
1504
|
+
throw err;
|
|
1505
|
+
} finally {
|
|
1506
|
+
setIsLoading(false);
|
|
1507
|
+
}
|
|
1508
|
+
}, [client]);
|
|
1509
|
+
const updateEvalRun = useCallback10(async (evalRunId, request, options) => {
|
|
1510
|
+
setIsLoading(true);
|
|
1511
|
+
setError(undefined);
|
|
1512
|
+
try {
|
|
1513
|
+
const result = await client.updateEvalRun(evalRunId, request, options);
|
|
1514
|
+
setEvalRuns((prev) => prev.map((evalRun) => evalRun.id === evalRunId ? result : evalRun));
|
|
1515
|
+
return result;
|
|
1516
|
+
} catch (err) {
|
|
1517
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1518
|
+
setError(errorMessage);
|
|
1519
|
+
throw err;
|
|
1520
|
+
} finally {
|
|
1521
|
+
setIsLoading(false);
|
|
1522
|
+
}
|
|
1523
|
+
}, [client]);
|
|
1524
|
+
const deleteEvalRuns = useCallback10(async (evalRunIds, options) => {
|
|
1525
|
+
setIsLoading(true);
|
|
1526
|
+
setError(undefined);
|
|
1527
|
+
try {
|
|
1528
|
+
await client.deleteEvalRuns(evalRunIds, options);
|
|
1529
|
+
const deletedSet = new Set(evalRunIds);
|
|
1530
|
+
setEvalRuns((prev) => prev.filter((evalRun) => !deletedSet.has(evalRun.id)));
|
|
1531
|
+
} catch (err) {
|
|
1532
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1533
|
+
setError(errorMessage);
|
|
1534
|
+
throw err;
|
|
1535
|
+
} finally {
|
|
1536
|
+
setIsLoading(false);
|
|
1537
|
+
}
|
|
1538
|
+
}, [client]);
|
|
1539
|
+
const renameEvalRun = useCallback10(async (evalRunId, newName, options) => {
|
|
1540
|
+
return updateEvalRun(evalRunId, { name: newName }, options);
|
|
1541
|
+
}, [updateEvalRun]);
|
|
1634
1542
|
return {
|
|
1635
|
-
// State
|
|
1636
1543
|
evalRuns,
|
|
1637
1544
|
pagination,
|
|
1638
1545
|
isLoading,
|
|
1639
1546
|
error,
|
|
1640
|
-
// Methods
|
|
1641
1547
|
listEvalRuns,
|
|
1642
1548
|
getEvalRun,
|
|
1643
1549
|
executeEval,
|
|
@@ -1646,7 +1552,6 @@ function useAgnoEvals() {
|
|
|
1646
1552
|
renameEvalRun
|
|
1647
1553
|
};
|
|
1648
1554
|
}
|
|
1649
|
-
|
|
1650
1555
|
// src/hooks/useAgnoTraces.ts
|
|
1651
1556
|
import { useState as useState11, useEffect as useEffect7, useCallback as useCallback11 } from "react";
|
|
1652
1557
|
function useAgnoTraces() {
|
|
@@ -1669,110 +1574,96 @@ function useAgnoTraces() {
|
|
|
1669
1574
|
client.off("state:change", handleStateChange);
|
|
1670
1575
|
};
|
|
1671
1576
|
}, [client]);
|
|
1672
|
-
const fetchTraces = useCallback11(
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
setError(
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1716
|
-
setError(errorMessage);
|
|
1717
|
-
throw err;
|
|
1718
|
-
} finally {
|
|
1719
|
-
setIsLoading(false);
|
|
1720
|
-
}
|
|
1721
|
-
},
|
|
1722
|
-
[client]
|
|
1723
|
-
);
|
|
1577
|
+
const fetchTraces = useCallback11(async (options = {}, requestOptions) => {
|
|
1578
|
+
setIsLoading(true);
|
|
1579
|
+
setError(undefined);
|
|
1580
|
+
try {
|
|
1581
|
+
const result = await client.fetchTraces(options, requestOptions);
|
|
1582
|
+
setTraces(result.traces);
|
|
1583
|
+
return result;
|
|
1584
|
+
} catch (err) {
|
|
1585
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1586
|
+
setError(errorMessage);
|
|
1587
|
+
throw err;
|
|
1588
|
+
} finally {
|
|
1589
|
+
setIsLoading(false);
|
|
1590
|
+
}
|
|
1591
|
+
}, [client]);
|
|
1592
|
+
const getTraceDetail = useCallback11(async (traceId, options = {}, requestOptions) => {
|
|
1593
|
+
setIsLoading(true);
|
|
1594
|
+
setError(undefined);
|
|
1595
|
+
try {
|
|
1596
|
+
return await client.getTraceDetail(traceId, options, requestOptions);
|
|
1597
|
+
} catch (err) {
|
|
1598
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1599
|
+
setError(errorMessage);
|
|
1600
|
+
throw err;
|
|
1601
|
+
} finally {
|
|
1602
|
+
setIsLoading(false);
|
|
1603
|
+
}
|
|
1604
|
+
}, [client]);
|
|
1605
|
+
const fetchTraceSessionStats = useCallback11(async (options = {}, requestOptions) => {
|
|
1606
|
+
setIsLoading(true);
|
|
1607
|
+
setError(undefined);
|
|
1608
|
+
try {
|
|
1609
|
+
const result = await client.fetchTraceSessionStats(options, requestOptions);
|
|
1610
|
+
setTraceSessionStats(result.stats);
|
|
1611
|
+
return result;
|
|
1612
|
+
} catch (err) {
|
|
1613
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
1614
|
+
setError(errorMessage);
|
|
1615
|
+
throw err;
|
|
1616
|
+
} finally {
|
|
1617
|
+
setIsLoading(false);
|
|
1618
|
+
}
|
|
1619
|
+
}, [client]);
|
|
1724
1620
|
return {
|
|
1725
|
-
/** Current list of traces (from last fetchTraces call) */
|
|
1726
1621
|
traces,
|
|
1727
|
-
/** Current trace session statistics (from last fetchTraceSessionStats call) */
|
|
1728
1622
|
traceSessionStats,
|
|
1729
|
-
/** Fetch traces with optional filters and pagination */
|
|
1730
1623
|
fetchTraces,
|
|
1731
|
-
/** Get trace detail or specific span */
|
|
1732
1624
|
getTraceDetail,
|
|
1733
|
-
/** Fetch trace session statistics */
|
|
1734
1625
|
fetchTraceSessionStats,
|
|
1735
|
-
/** Loading state */
|
|
1736
1626
|
isLoading,
|
|
1737
|
-
/** Error message if last operation failed */
|
|
1738
1627
|
error
|
|
1739
1628
|
};
|
|
1740
1629
|
}
|
|
1741
1630
|
export {
|
|
1742
|
-
|
|
1743
|
-
ComponentRegistry,
|
|
1744
|
-
GenerativeUIRenderer,
|
|
1745
|
-
ToolHandlerProvider,
|
|
1746
|
-
createAreaChart,
|
|
1747
|
-
createArtifact,
|
|
1748
|
-
createBarChart,
|
|
1749
|
-
createCard,
|
|
1750
|
-
createCardGrid,
|
|
1751
|
-
createColumn,
|
|
1752
|
-
createLineChart,
|
|
1753
|
-
createMarkdown,
|
|
1754
|
-
createPieChart,
|
|
1755
|
-
createSmartChart,
|
|
1756
|
-
createTable,
|
|
1757
|
-
createToolResult,
|
|
1758
|
-
getChartComponent,
|
|
1759
|
-
getComponentRegistry,
|
|
1760
|
-
getCustomRender,
|
|
1761
|
-
registerChartComponent,
|
|
1762
|
-
resultWithBarChart,
|
|
1763
|
-
resultWithCardGrid,
|
|
1764
|
-
resultWithSmartChart,
|
|
1765
|
-
resultWithTable,
|
|
1766
|
-
useAgnoActions,
|
|
1767
|
-
useAgnoChat,
|
|
1768
|
-
useAgnoClient,
|
|
1769
|
-
useAgnoCustomEvents,
|
|
1770
|
-
useAgnoEvals,
|
|
1771
|
-
useAgnoKnowledge,
|
|
1772
|
-
useAgnoMemory,
|
|
1773
|
-
useAgnoMetrics,
|
|
1774
|
-
useAgnoSession,
|
|
1775
|
-
useAgnoToolExecution,
|
|
1631
|
+
useToolHandlers,
|
|
1776
1632
|
useAgnoTraces,
|
|
1777
|
-
|
|
1633
|
+
useAgnoToolExecution,
|
|
1634
|
+
useAgnoSession,
|
|
1635
|
+
useAgnoMetrics,
|
|
1636
|
+
useAgnoMemory,
|
|
1637
|
+
useAgnoKnowledge,
|
|
1638
|
+
useAgnoEvals,
|
|
1639
|
+
useAgnoCustomEvents,
|
|
1640
|
+
useAgnoClient,
|
|
1641
|
+
useAgnoChat,
|
|
1642
|
+
useAgnoActions,
|
|
1643
|
+
resultWithTable,
|
|
1644
|
+
resultWithSmartChart,
|
|
1645
|
+
resultWithCardGrid,
|
|
1646
|
+
resultWithBarChart,
|
|
1647
|
+
registerChartComponent,
|
|
1648
|
+
getCustomRender,
|
|
1649
|
+
getComponentRegistry,
|
|
1650
|
+
getChartComponent,
|
|
1651
|
+
createToolResult,
|
|
1652
|
+
createTable,
|
|
1653
|
+
createSmartChart,
|
|
1654
|
+
createPieChart,
|
|
1655
|
+
createMarkdown,
|
|
1656
|
+
createLineChart,
|
|
1657
|
+
createColumn,
|
|
1658
|
+
createCardGrid,
|
|
1659
|
+
createCard,
|
|
1660
|
+
createBarChart,
|
|
1661
|
+
createArtifact,
|
|
1662
|
+
createAreaChart,
|
|
1663
|
+
ToolHandlerProvider,
|
|
1664
|
+
GenerativeUIRenderer,
|
|
1665
|
+
ComponentRegistry,
|
|
1666
|
+
AgnoProvider
|
|
1778
1667
|
};
|
|
1668
|
+
|
|
1669
|
+
//# debugId=414F45CD3B3482F064756E2164756E21
|