@antipopp/agno-react 0.10.0 → 0.12.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 +63 -1
- package/dist/index.d.mts +75 -38
- package/dist/index.d.ts +75 -38
- package/dist/index.js +346 -204
- package/dist/index.mjs +345 -205
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -38,6 +38,10 @@ function App() {
|
|
|
38
38
|
},
|
|
39
39
|
params: { // Optional: Global query params for all requests
|
|
40
40
|
locale: 'en-US'
|
|
41
|
+
},
|
|
42
|
+
dependencies: { // Optional: Global run dependencies for sendMessage
|
|
43
|
+
tenantId: 'tenant-1',
|
|
44
|
+
locale: 'en-US'
|
|
41
45
|
}
|
|
42
46
|
}}
|
|
43
47
|
>
|
|
@@ -133,9 +137,14 @@ await sendMessage('Hello!');
|
|
|
133
137
|
// Send with FormData (for file uploads)
|
|
134
138
|
const formData = new FormData();
|
|
135
139
|
formData.append('message', 'Hello!');
|
|
136
|
-
formData.append('
|
|
140
|
+
formData.append('files', file);
|
|
137
141
|
await sendMessage(formData);
|
|
138
142
|
|
|
143
|
+
// Send with files option
|
|
144
|
+
await sendMessage('Hello!', {
|
|
145
|
+
files: [file]
|
|
146
|
+
});
|
|
147
|
+
|
|
139
148
|
// Send with custom headers
|
|
140
149
|
await sendMessage('Hello!', {
|
|
141
150
|
headers: { 'X-Custom': 'value' }
|
|
@@ -151,6 +160,14 @@ await sendMessage('Hello!', {
|
|
|
151
160
|
headers: { 'X-Request-ID': '12345' },
|
|
152
161
|
params: { debug: 'true' }
|
|
153
162
|
});
|
|
163
|
+
|
|
164
|
+
// Send with per-request dependencies (merged with/override provider config)
|
|
165
|
+
await sendMessage('Hello!', {
|
|
166
|
+
dependencies: {
|
|
167
|
+
locale: 'fr-FR', // overrides global dependency
|
|
168
|
+
feature: 'rag' // merged as a new dependency key
|
|
169
|
+
}
|
|
170
|
+
});
|
|
154
171
|
```
|
|
155
172
|
|
|
156
173
|
#### `clearMessages()`
|
|
@@ -257,6 +274,51 @@ function InitComponent() {
|
|
|
257
274
|
}
|
|
258
275
|
```
|
|
259
276
|
|
|
277
|
+
### useAgnoToolExecution()
|
|
278
|
+
|
|
279
|
+
Hook for Human-in-the-Loop (HITL) frontend tool execution.
|
|
280
|
+
|
|
281
|
+
```tsx
|
|
282
|
+
import {
|
|
283
|
+
createToolArgsValidatorFromSafeParse,
|
|
284
|
+
createValidatedToolHandler,
|
|
285
|
+
type ToolHandler,
|
|
286
|
+
useAgnoToolExecution,
|
|
287
|
+
} from '@antipopp/agno-react';
|
|
288
|
+
import { z } from 'zod';
|
|
289
|
+
|
|
290
|
+
const navigateSchema = z.object({
|
|
291
|
+
url: z.string().url(),
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
const navigateValidator = createToolArgsValidatorFromSafeParse((args) =>
|
|
295
|
+
navigateSchema.safeParse(args)
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
const toolHandlers: Record<string, ToolHandler> = {
|
|
299
|
+
navigate_to_page: createValidatedToolHandler(navigateValidator, (args) => {
|
|
300
|
+
window.location.href = args.url;
|
|
301
|
+
return { success: true, url: args.url };
|
|
302
|
+
}),
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
function ChatWithTools() {
|
|
306
|
+
const { isPaused, isExecuting, pendingTools, executionError } =
|
|
307
|
+
useAgnoToolExecution(toolHandlers, true);
|
|
308
|
+
|
|
309
|
+
return <div>{isExecuting ? `Executing ${pendingTools.length} tools...` : null}</div>;
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Scope of this hook:
|
|
314
|
+
- Listens to paused run events and tracks execution state for your UI
|
|
315
|
+
- Executes local/global tool handlers and continues paused runs
|
|
316
|
+
- Supports auto execution or manual approval flows
|
|
317
|
+
- Hydrates tool-call UI components when sessions are loaded
|
|
318
|
+
|
|
319
|
+
Validation note:
|
|
320
|
+
- Tool arguments are runtime input. Prefer `createValidatedToolHandler()` with schema validation to avoid repeating manual guards.
|
|
321
|
+
|
|
260
322
|
## Complete Example
|
|
261
323
|
|
|
262
324
|
```tsx
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _antipopp_agno_types from '@antipopp/agno-types';
|
|
2
2
|
import { UIComponentSpec, AgnoClientConfig, ToolCall, CustomRenderFunction, AgentDetails, TeamDetails, ChatMessage, ClientState, SessionEntry, ChartComponentSpec, ArtifactComponentSpec, CardData, CardGridComponentSpec, TableColumn, MarkdownComponentSpec, TableComponentSpec, ToolHandlerResult } from '@antipopp/agno-types';
|
|
3
3
|
export { AgentDetails, AgnoClientConfig, ArtifactComponentSpec, CardData, CardGridComponentSpec, ChartComponentSpec, ChartSeries, ChatMessage, ClientState, CustomComponentSpec, GenerativeUIData, MarkdownComponentSpec, RunEvent, SessionEntry, TableColumn, TableComponentSpec, TeamDetails, ToolCall, ToolHandlerResult, UIComponentSpec } from '@antipopp/agno-types';
|
|
4
|
-
import React from 'react';
|
|
4
|
+
import React, { ReactNode } from 'react';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { AgnoClient } from '@antipopp/agno-client';
|
|
7
7
|
|
|
@@ -41,8 +41,14 @@ declare function useAgnoClient(): AgnoClient;
|
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Tool handler function type (now supports generative UI)
|
|
44
|
+
* - Receives normalized object arguments
|
|
45
|
+
* - Can return sync or async values
|
|
44
46
|
*/
|
|
45
|
-
type
|
|
47
|
+
type MaybePromise$1<T> = T | Promise<T>;
|
|
48
|
+
type ToolHandler<TArgs extends ToolCall["tool_args"] = ToolCall["tool_args"], TResult = unknown> = {
|
|
49
|
+
bivarianceHack(args: TArgs): MaybePromise$1<TResult>;
|
|
50
|
+
}["bivarianceHack"];
|
|
51
|
+
type ToolHandlers = Record<string, ToolHandler>;
|
|
46
52
|
/**
|
|
47
53
|
* Get a custom render function by key
|
|
48
54
|
*/
|
|
@@ -85,7 +91,7 @@ interface ToolExecutionEvent {
|
|
|
85
91
|
* const { isPaused, isExecuting, pendingTools } = useAgnoToolExecution(toolHandlers);
|
|
86
92
|
* ```
|
|
87
93
|
*/
|
|
88
|
-
declare function useAgnoToolExecution(handlers?:
|
|
94
|
+
declare function useAgnoToolExecution(handlers?: ToolHandlers, autoExecute?: boolean): {
|
|
89
95
|
/** Whether the run is currently paused awaiting tool execution */
|
|
90
96
|
isPaused: boolean;
|
|
91
97
|
/** Whether tools are currently being executed */
|
|
@@ -109,12 +115,12 @@ declare function useAgnoToolExecution(handlers?: Record<string, ToolHandler>, au
|
|
|
109
115
|
* Context value for tool handler registry
|
|
110
116
|
*/
|
|
111
117
|
interface ToolHandlerContextValue {
|
|
112
|
-
handlers:
|
|
118
|
+
handlers: ToolHandlers;
|
|
113
119
|
registerHandler: (name: string, handler: ToolHandler) => void;
|
|
114
120
|
unregisterHandler: (name: string) => void;
|
|
115
121
|
}
|
|
116
122
|
interface ToolHandlerProviderProps {
|
|
117
|
-
handlers?:
|
|
123
|
+
handlers?: ToolHandlers;
|
|
118
124
|
children: React.ReactNode;
|
|
119
125
|
}
|
|
120
126
|
/**
|
|
@@ -177,10 +183,7 @@ declare function useAgnoActions(): {
|
|
|
177
183
|
*/
|
|
178
184
|
declare function useAgnoChat(): {
|
|
179
185
|
messages: ChatMessage[];
|
|
180
|
-
sendMessage: (message: string | FormData, options?:
|
|
181
|
-
headers?: Record<string, string>;
|
|
182
|
-
params?: Record<string, string>;
|
|
183
|
-
}) => Promise<void>;
|
|
186
|
+
sendMessage: (message: string | FormData, options?: Parameters<(message: string | FormData, options?: _antipopp_agno_types.SendMessageOptions) => Promise<void>>[1]) => Promise<void>;
|
|
184
187
|
clearMessages: () => void;
|
|
185
188
|
cancelRun: () => Promise<void>;
|
|
186
189
|
isStreaming: boolean;
|
|
@@ -214,10 +217,11 @@ declare function useAgnoSession(): {
|
|
|
214
217
|
* Maps component specifications to actual React components.
|
|
215
218
|
* Allows registering custom components at runtime.
|
|
216
219
|
*/
|
|
220
|
+
|
|
217
221
|
/**
|
|
218
222
|
* Component renderer function type
|
|
219
223
|
*/
|
|
220
|
-
type ComponentRenderer = (props:
|
|
224
|
+
type ComponentRenderer = (props: Record<string, unknown>) => ReactNode;
|
|
221
225
|
/**
|
|
222
226
|
* Component registry class
|
|
223
227
|
*/
|
|
@@ -277,6 +281,49 @@ declare function registerChartComponent(name: string, renderer: ComponentRendere
|
|
|
277
281
|
*/
|
|
278
282
|
declare function getChartComponent(name: string): ComponentRenderer | undefined;
|
|
279
283
|
|
|
284
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
285
|
+
interface ToolArgsValidationSuccess<TArgs> {
|
|
286
|
+
success: true;
|
|
287
|
+
data: TArgs;
|
|
288
|
+
}
|
|
289
|
+
interface ToolArgsValidationFailure<TIssues = unknown> {
|
|
290
|
+
success: false;
|
|
291
|
+
message?: string;
|
|
292
|
+
issues?: TIssues;
|
|
293
|
+
}
|
|
294
|
+
type ToolArgsValidationResult<TArgs, TIssues = unknown> = ToolArgsValidationSuccess<TArgs> | ToolArgsValidationFailure<TIssues>;
|
|
295
|
+
type ToolArgsValidator<TArgs, TIssues = unknown> = (args: Record<string, unknown>) => MaybePromise<ToolArgsValidationResult<TArgs, TIssues>>;
|
|
296
|
+
interface ToolValidationError<TIssues = unknown> {
|
|
297
|
+
success: false;
|
|
298
|
+
code: "INVALID_TOOL_ARGS";
|
|
299
|
+
error: string;
|
|
300
|
+
issues?: TIssues;
|
|
301
|
+
}
|
|
302
|
+
interface CreateValidatedToolHandlerOptions<TIssues = unknown, TValidationError = ToolValidationError<TIssues>> {
|
|
303
|
+
errorMessage?: string;
|
|
304
|
+
mapValidationError?: (failure: ToolArgsValidationFailure<TIssues>, args: Record<string, unknown>) => TValidationError;
|
|
305
|
+
}
|
|
306
|
+
type SafeParseResult<TArgs, TIssues = unknown> = {
|
|
307
|
+
success: true;
|
|
308
|
+
data: TArgs;
|
|
309
|
+
} | {
|
|
310
|
+
success: false;
|
|
311
|
+
error: TIssues;
|
|
312
|
+
};
|
|
313
|
+
interface CreateValidatorFromSafeParseOptions<TIssues = unknown> {
|
|
314
|
+
getErrorMessage?: (issues: TIssues) => string;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Create a ToolArgsValidator from libraries that expose safeParse-like APIs.
|
|
318
|
+
*
|
|
319
|
+
* This is validator-agnostic and works with Zod, Valibot, ArkType adapters, etc.
|
|
320
|
+
*/
|
|
321
|
+
declare function createToolArgsValidatorFromSafeParse<TArgs, TIssues = unknown>(safeParse: (args: Record<string, unknown>) => MaybePromise<SafeParseResult<TArgs, TIssues>>, options?: CreateValidatorFromSafeParseOptions<TIssues>): ToolArgsValidator<TArgs, TIssues>;
|
|
322
|
+
/**
|
|
323
|
+
* Wrap a tool handler with runtime argument validation.
|
|
324
|
+
*/
|
|
325
|
+
declare function createValidatedToolHandler<TArgs, TResult = unknown, TIssues = unknown, TValidationError = ToolValidationError<TIssues>>(validator: ToolArgsValidator<TArgs, TIssues>, handler: (args: TArgs) => MaybePromise<TResult>, options?: CreateValidatedToolHandlerOptions<TIssues, TValidationError>): ToolHandler<Record<string, unknown>, TResult | TValidationError | ToolValidationError<TIssues>>;
|
|
326
|
+
|
|
280
327
|
/**
|
|
281
328
|
* Helper utilities for creating UI component specifications
|
|
282
329
|
*
|
|
@@ -284,6 +331,12 @@ declare function getChartComponent(name: string): ComponentRenderer | undefined;
|
|
|
284
331
|
* manually constructing the full specification object.
|
|
285
332
|
*/
|
|
286
333
|
|
|
334
|
+
type DataRow = Record<string, unknown>;
|
|
335
|
+
type SeriesInput = Array<{
|
|
336
|
+
key: string;
|
|
337
|
+
label?: string;
|
|
338
|
+
color?: string;
|
|
339
|
+
}>;
|
|
287
340
|
/**
|
|
288
341
|
* Chart helper options
|
|
289
342
|
*/
|
|
@@ -306,33 +359,21 @@ interface ChartHelperOptions {
|
|
|
306
359
|
/**
|
|
307
360
|
* Create a bar chart specification
|
|
308
361
|
*/
|
|
309
|
-
declare function createBarChart(data:
|
|
310
|
-
key: string;
|
|
311
|
-
label?: string;
|
|
312
|
-
color?: string;
|
|
313
|
-
}>, options?: ChartHelperOptions): ChartComponentSpec;
|
|
362
|
+
declare function createBarChart(data: DataRow[], xKey: string, bars: SeriesInput, options?: ChartHelperOptions): ChartComponentSpec;
|
|
314
363
|
/**
|
|
315
364
|
* Create a line chart specification
|
|
316
365
|
*/
|
|
317
|
-
declare function createLineChart(data:
|
|
318
|
-
key: string;
|
|
319
|
-
label?: string;
|
|
320
|
-
color?: string;
|
|
321
|
-
}>, options?: ChartHelperOptions): ChartComponentSpec;
|
|
366
|
+
declare function createLineChart(data: DataRow[], xKey: string, lines: SeriesInput, options?: ChartHelperOptions): ChartComponentSpec;
|
|
322
367
|
/**
|
|
323
368
|
* Create a pie chart specification
|
|
324
369
|
*/
|
|
325
|
-
declare function createPieChart(data:
|
|
370
|
+
declare function createPieChart(data: DataRow[], dataKey: string, nameKey: string, options?: ChartHelperOptions & {
|
|
326
371
|
showLabel?: boolean;
|
|
327
372
|
}): ChartComponentSpec;
|
|
328
373
|
/**
|
|
329
374
|
* Create an area chart specification
|
|
330
375
|
*/
|
|
331
|
-
declare function createAreaChart(data:
|
|
332
|
-
key: string;
|
|
333
|
-
label?: string;
|
|
334
|
-
color?: string;
|
|
335
|
-
}>, options?: ChartHelperOptions): ChartComponentSpec;
|
|
376
|
+
declare function createAreaChart(data: DataRow[], xKey: string, areas: SeriesInput, options?: ChartHelperOptions): ChartComponentSpec;
|
|
336
377
|
/**
|
|
337
378
|
* Card grid helper options
|
|
338
379
|
*/
|
|
@@ -358,7 +399,7 @@ declare function createCardGrid(cards: CardData[], options?: CardGridHelperOptio
|
|
|
358
399
|
*/
|
|
359
400
|
declare function createCard(id: string, title: string, description?: string, options?: {
|
|
360
401
|
image?: string;
|
|
361
|
-
metadata?: Record<string,
|
|
402
|
+
metadata?: Record<string, unknown>;
|
|
362
403
|
actions?: CardData["actions"];
|
|
363
404
|
}): CardData;
|
|
364
405
|
/**
|
|
@@ -379,7 +420,7 @@ interface TableHelperOptions {
|
|
|
379
420
|
/**
|
|
380
421
|
* Create a table specification
|
|
381
422
|
*/
|
|
382
|
-
declare function createTable(data:
|
|
423
|
+
declare function createTable(data: DataRow[], columns: TableColumn[], options?: TableHelperOptions): TableComponentSpec;
|
|
383
424
|
/**
|
|
384
425
|
* Create a table column definition
|
|
385
426
|
*/
|
|
@@ -409,7 +450,7 @@ declare function createArtifact(content: UIComponentSpec[], options?: {
|
|
|
409
450
|
/**
|
|
410
451
|
* Smart chart creator - automatically chooses the best chart type based on data
|
|
411
452
|
*/
|
|
412
|
-
declare function createSmartChart(data:
|
|
453
|
+
declare function createSmartChart(data: DataRow[], options?: {
|
|
413
454
|
title?: string;
|
|
414
455
|
description?: string;
|
|
415
456
|
layout?: "inline" | "artifact";
|
|
@@ -420,19 +461,15 @@ declare function createSmartChart(data: any[], options?: {
|
|
|
420
461
|
/**
|
|
421
462
|
* Wrap data and UI into a ToolHandlerResult
|
|
422
463
|
*/
|
|
423
|
-
declare function createToolResult(data:
|
|
464
|
+
declare function createToolResult(data: unknown, ui: UIComponentSpec): ToolHandlerResult;
|
|
424
465
|
/**
|
|
425
466
|
* Quick helper: create a tool result with a bar chart
|
|
426
467
|
*/
|
|
427
|
-
declare function resultWithBarChart(data:
|
|
428
|
-
key: string;
|
|
429
|
-
label?: string;
|
|
430
|
-
color?: string;
|
|
431
|
-
}>, options?: ChartHelperOptions): ToolHandlerResult;
|
|
468
|
+
declare function resultWithBarChart(data: DataRow[], xKey: string, bars: SeriesInput, options?: ChartHelperOptions): ToolHandlerResult;
|
|
432
469
|
/**
|
|
433
470
|
* Quick helper: create a tool result with a smart chart
|
|
434
471
|
*/
|
|
435
|
-
declare function resultWithSmartChart(data:
|
|
472
|
+
declare function resultWithSmartChart(data: DataRow[], options?: Parameters<typeof createSmartChart>[1]): ToolHandlerResult;
|
|
436
473
|
/**
|
|
437
474
|
* Quick helper: create a tool result with a card grid
|
|
438
475
|
*/
|
|
@@ -440,6 +477,6 @@ declare function resultWithCardGrid(cards: CardData[], options?: CardGridHelperO
|
|
|
440
477
|
/**
|
|
441
478
|
* Quick helper: create a tool result with a table
|
|
442
479
|
*/
|
|
443
|
-
declare function resultWithTable(data:
|
|
480
|
+
declare function resultWithTable(data: DataRow[], columns: TableColumn[], options?: TableHelperOptions): ToolHandlerResult;
|
|
444
481
|
|
|
445
|
-
export { AgnoProvider, type AgnoProviderProps, type CardGridHelperOptions, type ChartHelperOptions, ComponentRegistry, type ComponentRenderer, GenerativeUIRenderer, type GenerativeUIRendererProps, type TableHelperOptions, type ToolExecutionEvent, type ToolHandler, type ToolHandlerContextValue, ToolHandlerProvider, type ToolHandlerProviderProps, clearCustomRenderRegistry, createAreaChart, createArtifact, createBarChart, createCard, createCardGrid, createColumn, createLineChart, createMarkdown, createPieChart, createSmartChart, createTable, createToolResult, getChartComponent, getComponentRegistry, getCustomRender, registerChartComponent, resultWithBarChart, resultWithCardGrid, resultWithSmartChart, resultWithTable, useAgnoActions, useAgnoChat, useAgnoClient, useAgnoSession, useAgnoToolExecution, useToolHandlers };
|
|
482
|
+
export { AgnoProvider, type AgnoProviderProps, type CardGridHelperOptions, type ChartHelperOptions, ComponentRegistry, type ComponentRenderer, type CreateValidatedToolHandlerOptions, type CreateValidatorFromSafeParseOptions, GenerativeUIRenderer, type GenerativeUIRendererProps, type SafeParseResult, type TableHelperOptions, type ToolArgsValidationFailure, type ToolArgsValidationResult, type ToolArgsValidationSuccess, type ToolArgsValidator, type ToolExecutionEvent, type ToolHandler, type ToolHandlerContextValue, ToolHandlerProvider, type ToolHandlerProviderProps, type ToolHandlers, type ToolValidationError, clearCustomRenderRegistry, createAreaChart, createArtifact, createBarChart, createCard, createCardGrid, createColumn, createLineChart, createMarkdown, createPieChart, createSmartChart, createTable, createToolArgsValidatorFromSafeParse, createToolResult, createValidatedToolHandler, getChartComponent, getComponentRegistry, getCustomRender, registerChartComponent, resultWithBarChart, resultWithCardGrid, resultWithSmartChart, resultWithTable, useAgnoActions, useAgnoChat, useAgnoClient, useAgnoSession, useAgnoToolExecution, useToolHandlers };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _antipopp_agno_types from '@antipopp/agno-types';
|
|
2
2
|
import { UIComponentSpec, AgnoClientConfig, ToolCall, CustomRenderFunction, AgentDetails, TeamDetails, ChatMessage, ClientState, SessionEntry, ChartComponentSpec, ArtifactComponentSpec, CardData, CardGridComponentSpec, TableColumn, MarkdownComponentSpec, TableComponentSpec, ToolHandlerResult } from '@antipopp/agno-types';
|
|
3
3
|
export { AgentDetails, AgnoClientConfig, ArtifactComponentSpec, CardData, CardGridComponentSpec, ChartComponentSpec, ChartSeries, ChatMessage, ClientState, CustomComponentSpec, GenerativeUIData, MarkdownComponentSpec, RunEvent, SessionEntry, TableColumn, TableComponentSpec, TeamDetails, ToolCall, ToolHandlerResult, UIComponentSpec } from '@antipopp/agno-types';
|
|
4
|
-
import React from 'react';
|
|
4
|
+
import React, { ReactNode } from 'react';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { AgnoClient } from '@antipopp/agno-client';
|
|
7
7
|
|
|
@@ -41,8 +41,14 @@ declare function useAgnoClient(): AgnoClient;
|
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Tool handler function type (now supports generative UI)
|
|
44
|
+
* - Receives normalized object arguments
|
|
45
|
+
* - Can return sync or async values
|
|
44
46
|
*/
|
|
45
|
-
type
|
|
47
|
+
type MaybePromise$1<T> = T | Promise<T>;
|
|
48
|
+
type ToolHandler<TArgs extends ToolCall["tool_args"] = ToolCall["tool_args"], TResult = unknown> = {
|
|
49
|
+
bivarianceHack(args: TArgs): MaybePromise$1<TResult>;
|
|
50
|
+
}["bivarianceHack"];
|
|
51
|
+
type ToolHandlers = Record<string, ToolHandler>;
|
|
46
52
|
/**
|
|
47
53
|
* Get a custom render function by key
|
|
48
54
|
*/
|
|
@@ -85,7 +91,7 @@ interface ToolExecutionEvent {
|
|
|
85
91
|
* const { isPaused, isExecuting, pendingTools } = useAgnoToolExecution(toolHandlers);
|
|
86
92
|
* ```
|
|
87
93
|
*/
|
|
88
|
-
declare function useAgnoToolExecution(handlers?:
|
|
94
|
+
declare function useAgnoToolExecution(handlers?: ToolHandlers, autoExecute?: boolean): {
|
|
89
95
|
/** Whether the run is currently paused awaiting tool execution */
|
|
90
96
|
isPaused: boolean;
|
|
91
97
|
/** Whether tools are currently being executed */
|
|
@@ -109,12 +115,12 @@ declare function useAgnoToolExecution(handlers?: Record<string, ToolHandler>, au
|
|
|
109
115
|
* Context value for tool handler registry
|
|
110
116
|
*/
|
|
111
117
|
interface ToolHandlerContextValue {
|
|
112
|
-
handlers:
|
|
118
|
+
handlers: ToolHandlers;
|
|
113
119
|
registerHandler: (name: string, handler: ToolHandler) => void;
|
|
114
120
|
unregisterHandler: (name: string) => void;
|
|
115
121
|
}
|
|
116
122
|
interface ToolHandlerProviderProps {
|
|
117
|
-
handlers?:
|
|
123
|
+
handlers?: ToolHandlers;
|
|
118
124
|
children: React.ReactNode;
|
|
119
125
|
}
|
|
120
126
|
/**
|
|
@@ -177,10 +183,7 @@ declare function useAgnoActions(): {
|
|
|
177
183
|
*/
|
|
178
184
|
declare function useAgnoChat(): {
|
|
179
185
|
messages: ChatMessage[];
|
|
180
|
-
sendMessage: (message: string | FormData, options?:
|
|
181
|
-
headers?: Record<string, string>;
|
|
182
|
-
params?: Record<string, string>;
|
|
183
|
-
}) => Promise<void>;
|
|
186
|
+
sendMessage: (message: string | FormData, options?: Parameters<(message: string | FormData, options?: _antipopp_agno_types.SendMessageOptions) => Promise<void>>[1]) => Promise<void>;
|
|
184
187
|
clearMessages: () => void;
|
|
185
188
|
cancelRun: () => Promise<void>;
|
|
186
189
|
isStreaming: boolean;
|
|
@@ -214,10 +217,11 @@ declare function useAgnoSession(): {
|
|
|
214
217
|
* Maps component specifications to actual React components.
|
|
215
218
|
* Allows registering custom components at runtime.
|
|
216
219
|
*/
|
|
220
|
+
|
|
217
221
|
/**
|
|
218
222
|
* Component renderer function type
|
|
219
223
|
*/
|
|
220
|
-
type ComponentRenderer = (props:
|
|
224
|
+
type ComponentRenderer = (props: Record<string, unknown>) => ReactNode;
|
|
221
225
|
/**
|
|
222
226
|
* Component registry class
|
|
223
227
|
*/
|
|
@@ -277,6 +281,49 @@ declare function registerChartComponent(name: string, renderer: ComponentRendere
|
|
|
277
281
|
*/
|
|
278
282
|
declare function getChartComponent(name: string): ComponentRenderer | undefined;
|
|
279
283
|
|
|
284
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
285
|
+
interface ToolArgsValidationSuccess<TArgs> {
|
|
286
|
+
success: true;
|
|
287
|
+
data: TArgs;
|
|
288
|
+
}
|
|
289
|
+
interface ToolArgsValidationFailure<TIssues = unknown> {
|
|
290
|
+
success: false;
|
|
291
|
+
message?: string;
|
|
292
|
+
issues?: TIssues;
|
|
293
|
+
}
|
|
294
|
+
type ToolArgsValidationResult<TArgs, TIssues = unknown> = ToolArgsValidationSuccess<TArgs> | ToolArgsValidationFailure<TIssues>;
|
|
295
|
+
type ToolArgsValidator<TArgs, TIssues = unknown> = (args: Record<string, unknown>) => MaybePromise<ToolArgsValidationResult<TArgs, TIssues>>;
|
|
296
|
+
interface ToolValidationError<TIssues = unknown> {
|
|
297
|
+
success: false;
|
|
298
|
+
code: "INVALID_TOOL_ARGS";
|
|
299
|
+
error: string;
|
|
300
|
+
issues?: TIssues;
|
|
301
|
+
}
|
|
302
|
+
interface CreateValidatedToolHandlerOptions<TIssues = unknown, TValidationError = ToolValidationError<TIssues>> {
|
|
303
|
+
errorMessage?: string;
|
|
304
|
+
mapValidationError?: (failure: ToolArgsValidationFailure<TIssues>, args: Record<string, unknown>) => TValidationError;
|
|
305
|
+
}
|
|
306
|
+
type SafeParseResult<TArgs, TIssues = unknown> = {
|
|
307
|
+
success: true;
|
|
308
|
+
data: TArgs;
|
|
309
|
+
} | {
|
|
310
|
+
success: false;
|
|
311
|
+
error: TIssues;
|
|
312
|
+
};
|
|
313
|
+
interface CreateValidatorFromSafeParseOptions<TIssues = unknown> {
|
|
314
|
+
getErrorMessage?: (issues: TIssues) => string;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Create a ToolArgsValidator from libraries that expose safeParse-like APIs.
|
|
318
|
+
*
|
|
319
|
+
* This is validator-agnostic and works with Zod, Valibot, ArkType adapters, etc.
|
|
320
|
+
*/
|
|
321
|
+
declare function createToolArgsValidatorFromSafeParse<TArgs, TIssues = unknown>(safeParse: (args: Record<string, unknown>) => MaybePromise<SafeParseResult<TArgs, TIssues>>, options?: CreateValidatorFromSafeParseOptions<TIssues>): ToolArgsValidator<TArgs, TIssues>;
|
|
322
|
+
/**
|
|
323
|
+
* Wrap a tool handler with runtime argument validation.
|
|
324
|
+
*/
|
|
325
|
+
declare function createValidatedToolHandler<TArgs, TResult = unknown, TIssues = unknown, TValidationError = ToolValidationError<TIssues>>(validator: ToolArgsValidator<TArgs, TIssues>, handler: (args: TArgs) => MaybePromise<TResult>, options?: CreateValidatedToolHandlerOptions<TIssues, TValidationError>): ToolHandler<Record<string, unknown>, TResult | TValidationError | ToolValidationError<TIssues>>;
|
|
326
|
+
|
|
280
327
|
/**
|
|
281
328
|
* Helper utilities for creating UI component specifications
|
|
282
329
|
*
|
|
@@ -284,6 +331,12 @@ declare function getChartComponent(name: string): ComponentRenderer | undefined;
|
|
|
284
331
|
* manually constructing the full specification object.
|
|
285
332
|
*/
|
|
286
333
|
|
|
334
|
+
type DataRow = Record<string, unknown>;
|
|
335
|
+
type SeriesInput = Array<{
|
|
336
|
+
key: string;
|
|
337
|
+
label?: string;
|
|
338
|
+
color?: string;
|
|
339
|
+
}>;
|
|
287
340
|
/**
|
|
288
341
|
* Chart helper options
|
|
289
342
|
*/
|
|
@@ -306,33 +359,21 @@ interface ChartHelperOptions {
|
|
|
306
359
|
/**
|
|
307
360
|
* Create a bar chart specification
|
|
308
361
|
*/
|
|
309
|
-
declare function createBarChart(data:
|
|
310
|
-
key: string;
|
|
311
|
-
label?: string;
|
|
312
|
-
color?: string;
|
|
313
|
-
}>, options?: ChartHelperOptions): ChartComponentSpec;
|
|
362
|
+
declare function createBarChart(data: DataRow[], xKey: string, bars: SeriesInput, options?: ChartHelperOptions): ChartComponentSpec;
|
|
314
363
|
/**
|
|
315
364
|
* Create a line chart specification
|
|
316
365
|
*/
|
|
317
|
-
declare function createLineChart(data:
|
|
318
|
-
key: string;
|
|
319
|
-
label?: string;
|
|
320
|
-
color?: string;
|
|
321
|
-
}>, options?: ChartHelperOptions): ChartComponentSpec;
|
|
366
|
+
declare function createLineChart(data: DataRow[], xKey: string, lines: SeriesInput, options?: ChartHelperOptions): ChartComponentSpec;
|
|
322
367
|
/**
|
|
323
368
|
* Create a pie chart specification
|
|
324
369
|
*/
|
|
325
|
-
declare function createPieChart(data:
|
|
370
|
+
declare function createPieChart(data: DataRow[], dataKey: string, nameKey: string, options?: ChartHelperOptions & {
|
|
326
371
|
showLabel?: boolean;
|
|
327
372
|
}): ChartComponentSpec;
|
|
328
373
|
/**
|
|
329
374
|
* Create an area chart specification
|
|
330
375
|
*/
|
|
331
|
-
declare function createAreaChart(data:
|
|
332
|
-
key: string;
|
|
333
|
-
label?: string;
|
|
334
|
-
color?: string;
|
|
335
|
-
}>, options?: ChartHelperOptions): ChartComponentSpec;
|
|
376
|
+
declare function createAreaChart(data: DataRow[], xKey: string, areas: SeriesInput, options?: ChartHelperOptions): ChartComponentSpec;
|
|
336
377
|
/**
|
|
337
378
|
* Card grid helper options
|
|
338
379
|
*/
|
|
@@ -358,7 +399,7 @@ declare function createCardGrid(cards: CardData[], options?: CardGridHelperOptio
|
|
|
358
399
|
*/
|
|
359
400
|
declare function createCard(id: string, title: string, description?: string, options?: {
|
|
360
401
|
image?: string;
|
|
361
|
-
metadata?: Record<string,
|
|
402
|
+
metadata?: Record<string, unknown>;
|
|
362
403
|
actions?: CardData["actions"];
|
|
363
404
|
}): CardData;
|
|
364
405
|
/**
|
|
@@ -379,7 +420,7 @@ interface TableHelperOptions {
|
|
|
379
420
|
/**
|
|
380
421
|
* Create a table specification
|
|
381
422
|
*/
|
|
382
|
-
declare function createTable(data:
|
|
423
|
+
declare function createTable(data: DataRow[], columns: TableColumn[], options?: TableHelperOptions): TableComponentSpec;
|
|
383
424
|
/**
|
|
384
425
|
* Create a table column definition
|
|
385
426
|
*/
|
|
@@ -409,7 +450,7 @@ declare function createArtifact(content: UIComponentSpec[], options?: {
|
|
|
409
450
|
/**
|
|
410
451
|
* Smart chart creator - automatically chooses the best chart type based on data
|
|
411
452
|
*/
|
|
412
|
-
declare function createSmartChart(data:
|
|
453
|
+
declare function createSmartChart(data: DataRow[], options?: {
|
|
413
454
|
title?: string;
|
|
414
455
|
description?: string;
|
|
415
456
|
layout?: "inline" | "artifact";
|
|
@@ -420,19 +461,15 @@ declare function createSmartChart(data: any[], options?: {
|
|
|
420
461
|
/**
|
|
421
462
|
* Wrap data and UI into a ToolHandlerResult
|
|
422
463
|
*/
|
|
423
|
-
declare function createToolResult(data:
|
|
464
|
+
declare function createToolResult(data: unknown, ui: UIComponentSpec): ToolHandlerResult;
|
|
424
465
|
/**
|
|
425
466
|
* Quick helper: create a tool result with a bar chart
|
|
426
467
|
*/
|
|
427
|
-
declare function resultWithBarChart(data:
|
|
428
|
-
key: string;
|
|
429
|
-
label?: string;
|
|
430
|
-
color?: string;
|
|
431
|
-
}>, options?: ChartHelperOptions): ToolHandlerResult;
|
|
468
|
+
declare function resultWithBarChart(data: DataRow[], xKey: string, bars: SeriesInput, options?: ChartHelperOptions): ToolHandlerResult;
|
|
432
469
|
/**
|
|
433
470
|
* Quick helper: create a tool result with a smart chart
|
|
434
471
|
*/
|
|
435
|
-
declare function resultWithSmartChart(data:
|
|
472
|
+
declare function resultWithSmartChart(data: DataRow[], options?: Parameters<typeof createSmartChart>[1]): ToolHandlerResult;
|
|
436
473
|
/**
|
|
437
474
|
* Quick helper: create a tool result with a card grid
|
|
438
475
|
*/
|
|
@@ -440,6 +477,6 @@ declare function resultWithCardGrid(cards: CardData[], options?: CardGridHelperO
|
|
|
440
477
|
/**
|
|
441
478
|
* Quick helper: create a tool result with a table
|
|
442
479
|
*/
|
|
443
|
-
declare function resultWithTable(data:
|
|
480
|
+
declare function resultWithTable(data: DataRow[], columns: TableColumn[], options?: TableHelperOptions): ToolHandlerResult;
|
|
444
481
|
|
|
445
|
-
export { AgnoProvider, type AgnoProviderProps, type CardGridHelperOptions, type ChartHelperOptions, ComponentRegistry, type ComponentRenderer, GenerativeUIRenderer, type GenerativeUIRendererProps, type TableHelperOptions, type ToolExecutionEvent, type ToolHandler, type ToolHandlerContextValue, ToolHandlerProvider, type ToolHandlerProviderProps, clearCustomRenderRegistry, createAreaChart, createArtifact, createBarChart, createCard, createCardGrid, createColumn, createLineChart, createMarkdown, createPieChart, createSmartChart, createTable, createToolResult, getChartComponent, getComponentRegistry, getCustomRender, registerChartComponent, resultWithBarChart, resultWithCardGrid, resultWithSmartChart, resultWithTable, useAgnoActions, useAgnoChat, useAgnoClient, useAgnoSession, useAgnoToolExecution, useToolHandlers };
|
|
482
|
+
export { AgnoProvider, type AgnoProviderProps, type CardGridHelperOptions, type ChartHelperOptions, ComponentRegistry, type ComponentRenderer, type CreateValidatedToolHandlerOptions, type CreateValidatorFromSafeParseOptions, GenerativeUIRenderer, type GenerativeUIRendererProps, type SafeParseResult, type TableHelperOptions, type ToolArgsValidationFailure, type ToolArgsValidationResult, type ToolArgsValidationSuccess, type ToolArgsValidator, type ToolExecutionEvent, type ToolHandler, type ToolHandlerContextValue, ToolHandlerProvider, type ToolHandlerProviderProps, type ToolHandlers, type ToolValidationError, clearCustomRenderRegistry, createAreaChart, createArtifact, createBarChart, createCard, createCardGrid, createColumn, createLineChart, createMarkdown, createPieChart, createSmartChart, createTable, createToolArgsValidatorFromSafeParse, createToolResult, createValidatedToolHandler, getChartComponent, getComponentRegistry, getCustomRender, registerChartComponent, resultWithBarChart, resultWithCardGrid, resultWithSmartChart, resultWithTable, useAgnoActions, useAgnoChat, useAgnoClient, useAgnoSession, useAgnoToolExecution, useToolHandlers };
|