@antipopp/agno-client 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -0
- package/dist/index.d.mts +42 -15
- package/dist/index.d.ts +42 -15
- package/dist/index.js +474 -293
- package/dist/index.mjs +476 -293
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -68,6 +68,8 @@ new AgnoClient(config: AgnoClientConfig)
|
|
|
68
68
|
- `dbId` (string, optional) - Database ID
|
|
69
69
|
- `sessionId` (string, optional) - Current session ID
|
|
70
70
|
- `userId` (string, optional) - User ID to link sessions to a specific user
|
|
71
|
+
- `headers` (Record<string, string>, optional) - Global custom headers for all API requests
|
|
72
|
+
- `params` (Record<string, string>, optional) - Global query parameters for all API requests
|
|
71
73
|
|
|
72
74
|
### Methods
|
|
73
75
|
|
|
@@ -88,6 +90,17 @@ await client.sendMessage(formData);
|
|
|
88
90
|
await client.sendMessage('Hello!', {
|
|
89
91
|
headers: { 'X-Custom-Header': 'value' }
|
|
90
92
|
});
|
|
93
|
+
|
|
94
|
+
// With query parameters
|
|
95
|
+
await client.sendMessage('Hello!', {
|
|
96
|
+
params: { temperature: '0.7', max_tokens: '500' }
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// With both headers and params
|
|
100
|
+
await client.sendMessage('Hello!', {
|
|
101
|
+
headers: { 'X-Request-ID': '12345' },
|
|
102
|
+
params: { debug: 'true' }
|
|
103
|
+
});
|
|
91
104
|
```
|
|
92
105
|
|
|
93
106
|
#### `getMessages()`
|
|
@@ -241,6 +254,94 @@ try {
|
|
|
241
254
|
}
|
|
242
255
|
```
|
|
243
256
|
|
|
257
|
+
### Custom Headers and Query Parameters
|
|
258
|
+
|
|
259
|
+
The client supports both global and per-request headers and query parameters.
|
|
260
|
+
|
|
261
|
+
#### Global Configuration
|
|
262
|
+
|
|
263
|
+
Set headers and params in the client config to apply them to all API requests:
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
const client = new AgnoClient({
|
|
267
|
+
endpoint: 'http://localhost:7777',
|
|
268
|
+
agentId: 'agent-123',
|
|
269
|
+
headers: {
|
|
270
|
+
'X-API-Version': 'v2',
|
|
271
|
+
'X-Client-ID': 'my-app'
|
|
272
|
+
},
|
|
273
|
+
params: {
|
|
274
|
+
locale: 'en-US',
|
|
275
|
+
environment: 'production'
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
#### Per-Request Options
|
|
281
|
+
|
|
282
|
+
Override or add headers/params for specific requests:
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
// Per-request overrides global settings
|
|
286
|
+
await client.sendMessage('Hello!', {
|
|
287
|
+
headers: { 'X-Request-ID': '12345' },
|
|
288
|
+
params: { temperature: '0.7' }
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// All methods support headers and params
|
|
292
|
+
await client.loadSession('session-123', {
|
|
293
|
+
params: { include_metadata: 'true' }
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
await client.fetchSessions({
|
|
297
|
+
params: { limit: '50', status: 'active' }
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
await client.continueRun(tools, {
|
|
301
|
+
headers: { 'X-Trace-ID': 'abc123' },
|
|
302
|
+
params: { debug: 'true' }
|
|
303
|
+
});
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
#### Merge Behavior
|
|
307
|
+
|
|
308
|
+
**Headers:**
|
|
309
|
+
1. Global headers from `config.headers` (lowest precedence)
|
|
310
|
+
2. Per-request headers (overrides global)
|
|
311
|
+
3. Authorization header from `authToken` (highest precedence - always overrides)
|
|
312
|
+
|
|
313
|
+
**Query Parameters:**
|
|
314
|
+
1. Global params from `config.params` (lowest precedence)
|
|
315
|
+
2. Per-request params (highest precedence - overrides global)
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
const client = new AgnoClient({
|
|
319
|
+
endpoint: 'http://localhost:7777',
|
|
320
|
+
agentId: 'agent-123',
|
|
321
|
+
params: { version: 'v1', locale: 'en-US' }
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// This request will have: version=v2 (overridden), locale=en-US (from global), debug=true (added)
|
|
325
|
+
await client.sendMessage('Hello!', {
|
|
326
|
+
params: { version: 'v2', debug: 'true' }
|
|
327
|
+
});
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
#### Common Use Cases
|
|
331
|
+
|
|
332
|
+
**Headers:**
|
|
333
|
+
- Request tracking: `{ 'X-Request-ID': uuid() }`
|
|
334
|
+
- API versioning: `{ 'X-API-Version': 'v2' }`
|
|
335
|
+
- Client identification: `{ 'X-Client-ID': 'mobile-app' }`
|
|
336
|
+
- Custom auth: `{ 'X-Custom-Auth': 'token' }`
|
|
337
|
+
|
|
338
|
+
**Query Parameters:**
|
|
339
|
+
- Model configuration: `{ temperature: '0.7', max_tokens: '500' }`
|
|
340
|
+
- Feature flags: `{ enable_streaming: 'true' }`
|
|
341
|
+
- Locale/language: `{ locale: 'en-US', timezone: 'America/New_York' }`
|
|
342
|
+
- Debugging: `{ debug: 'true', trace_id: 'xyz' }`
|
|
343
|
+
- Pagination: `{ page: '1', limit: '50' }`
|
|
344
|
+
|
|
244
345
|
### Request Cancellation
|
|
245
346
|
|
|
246
347
|
Use `AbortController` to cancel ongoing requests. This is essential for preventing memory leaks when components unmount or users navigate away during streaming:
|
package/dist/index.d.mts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import EventEmitter from 'eventemitter3';
|
|
2
1
|
import { AgnoClientConfig, ChatMessage, ClientState, SessionEntry, ToolCall, AgentDetails, TeamDetails } from '@antipopp/agno-types';
|
|
3
2
|
export { AgentDetails, AgnoClientConfig, AudioData, ChatMessage, ClientState, ImageData, MessageExtraData, ResponseAudioData, RunEvent, RunResponse, RunResponseContent, SessionEntry, TeamDetails, ToolCall, VideoData } from '@antipopp/agno-types';
|
|
3
|
+
import EventEmitter from 'eventemitter3';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Main Agno client class
|
|
7
7
|
* Provides stateful management of agent/team interactions with streaming support
|
|
8
8
|
*/
|
|
9
9
|
declare class AgnoClient extends EventEmitter {
|
|
10
|
-
private messageStore;
|
|
11
|
-
private configManager;
|
|
12
|
-
private sessionManager;
|
|
13
|
-
private eventProcessor;
|
|
14
|
-
private state;
|
|
15
|
-
private pendingUISpecs;
|
|
10
|
+
private readonly messageStore;
|
|
11
|
+
private readonly configManager;
|
|
12
|
+
private readonly sessionManager;
|
|
13
|
+
private readonly eventProcessor;
|
|
14
|
+
private readonly state;
|
|
15
|
+
private readonly pendingUISpecs;
|
|
16
16
|
private runCompletedSuccessfully;
|
|
17
|
+
private currentRunId;
|
|
17
18
|
constructor(config: AgnoClientConfig);
|
|
18
19
|
/**
|
|
19
20
|
* Get current messages
|
|
@@ -35,11 +36,16 @@ declare class AgnoClient extends EventEmitter {
|
|
|
35
36
|
* Clear all messages
|
|
36
37
|
*/
|
|
37
38
|
clearMessages(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Cancel an active or paused run
|
|
41
|
+
*/
|
|
42
|
+
cancelRun(): Promise<void>;
|
|
38
43
|
/**
|
|
39
44
|
* Send a message to the agent/team (streaming)
|
|
40
45
|
*/
|
|
41
46
|
sendMessage(message: string | FormData, options?: {
|
|
42
47
|
headers?: Record<string, string>;
|
|
48
|
+
params?: Record<string, string>;
|
|
43
49
|
}): Promise<void>;
|
|
44
50
|
/**
|
|
45
51
|
* Handle streaming chunk
|
|
@@ -59,15 +65,21 @@ declare class AgnoClient extends EventEmitter {
|
|
|
59
65
|
/**
|
|
60
66
|
* Load a session
|
|
61
67
|
*/
|
|
62
|
-
loadSession(sessionId: string
|
|
68
|
+
loadSession(sessionId: string, options?: {
|
|
69
|
+
params?: Record<string, string>;
|
|
70
|
+
}): Promise<ChatMessage[]>;
|
|
63
71
|
/**
|
|
64
72
|
* Fetch all sessions
|
|
65
73
|
*/
|
|
66
|
-
fetchSessions(
|
|
74
|
+
fetchSessions(options?: {
|
|
75
|
+
params?: Record<string, string>;
|
|
76
|
+
}): Promise<SessionEntry[]>;
|
|
67
77
|
/**
|
|
68
78
|
* Delete a session
|
|
69
79
|
*/
|
|
70
|
-
deleteSession(sessionId: string
|
|
80
|
+
deleteSession(sessionId: string, options?: {
|
|
81
|
+
params?: Record<string, string>;
|
|
82
|
+
}): Promise<void>;
|
|
71
83
|
/**
|
|
72
84
|
* Add tool calls to the last message
|
|
73
85
|
* Used by frontend execution to add tool calls that were executed locally
|
|
@@ -91,33 +103,48 @@ declare class AgnoClient extends EventEmitter {
|
|
|
91
103
|
* Teams do not support the continue endpoint.
|
|
92
104
|
*
|
|
93
105
|
* @param tools - Array of tool calls with execution results
|
|
94
|
-
* @param options - Optional request headers
|
|
106
|
+
* @param options - Optional request headers and query parameters
|
|
95
107
|
* @throws Error if no paused run exists
|
|
96
108
|
* @throws Error if called with team mode (teams don't support HITL)
|
|
97
109
|
*/
|
|
98
110
|
continueRun(tools: ToolCall[], options?: {
|
|
99
111
|
headers?: Record<string, string>;
|
|
112
|
+
params?: Record<string, string>;
|
|
100
113
|
}): Promise<void>;
|
|
101
114
|
/**
|
|
102
115
|
* Check endpoint status
|
|
103
116
|
*/
|
|
104
|
-
checkStatus(
|
|
117
|
+
checkStatus(options?: {
|
|
118
|
+
params?: Record<string, string>;
|
|
119
|
+
}): Promise<boolean>;
|
|
105
120
|
/**
|
|
106
121
|
* Fetch agents from endpoint
|
|
107
122
|
*/
|
|
108
|
-
fetchAgents(
|
|
123
|
+
fetchAgents(options?: {
|
|
124
|
+
params?: Record<string, string>;
|
|
125
|
+
}): Promise<AgentDetails[]>;
|
|
109
126
|
/**
|
|
110
127
|
* Fetch teams from endpoint
|
|
111
128
|
*/
|
|
112
|
-
fetchTeams(
|
|
129
|
+
fetchTeams(options?: {
|
|
130
|
+
params?: Record<string, string>;
|
|
131
|
+
}): Promise<TeamDetails[]>;
|
|
113
132
|
/**
|
|
114
133
|
* Initialize client (check status and fetch agents/teams)
|
|
115
134
|
* Automatically selects the first available agent or team if none is configured
|
|
116
135
|
*/
|
|
117
|
-
initialize(
|
|
136
|
+
initialize(options?: {
|
|
137
|
+
params?: Record<string, string>;
|
|
138
|
+
}): Promise<{
|
|
118
139
|
agents: AgentDetails[];
|
|
119
140
|
teams: TeamDetails[];
|
|
120
141
|
}>;
|
|
142
|
+
/**
|
|
143
|
+
* Dispose of the client and clean up all resources.
|
|
144
|
+
* Call this method when the client is no longer needed to prevent memory leaks.
|
|
145
|
+
* After calling dispose(), the client instance should not be reused.
|
|
146
|
+
*/
|
|
147
|
+
dispose(): void;
|
|
121
148
|
}
|
|
122
149
|
|
|
123
150
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import EventEmitter from 'eventemitter3';
|
|
2
1
|
import { AgnoClientConfig, ChatMessage, ClientState, SessionEntry, ToolCall, AgentDetails, TeamDetails } from '@antipopp/agno-types';
|
|
3
2
|
export { AgentDetails, AgnoClientConfig, AudioData, ChatMessage, ClientState, ImageData, MessageExtraData, ResponseAudioData, RunEvent, RunResponse, RunResponseContent, SessionEntry, TeamDetails, ToolCall, VideoData } from '@antipopp/agno-types';
|
|
3
|
+
import EventEmitter from 'eventemitter3';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Main Agno client class
|
|
7
7
|
* Provides stateful management of agent/team interactions with streaming support
|
|
8
8
|
*/
|
|
9
9
|
declare class AgnoClient extends EventEmitter {
|
|
10
|
-
private messageStore;
|
|
11
|
-
private configManager;
|
|
12
|
-
private sessionManager;
|
|
13
|
-
private eventProcessor;
|
|
14
|
-
private state;
|
|
15
|
-
private pendingUISpecs;
|
|
10
|
+
private readonly messageStore;
|
|
11
|
+
private readonly configManager;
|
|
12
|
+
private readonly sessionManager;
|
|
13
|
+
private readonly eventProcessor;
|
|
14
|
+
private readonly state;
|
|
15
|
+
private readonly pendingUISpecs;
|
|
16
16
|
private runCompletedSuccessfully;
|
|
17
|
+
private currentRunId;
|
|
17
18
|
constructor(config: AgnoClientConfig);
|
|
18
19
|
/**
|
|
19
20
|
* Get current messages
|
|
@@ -35,11 +36,16 @@ declare class AgnoClient extends EventEmitter {
|
|
|
35
36
|
* Clear all messages
|
|
36
37
|
*/
|
|
37
38
|
clearMessages(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Cancel an active or paused run
|
|
41
|
+
*/
|
|
42
|
+
cancelRun(): Promise<void>;
|
|
38
43
|
/**
|
|
39
44
|
* Send a message to the agent/team (streaming)
|
|
40
45
|
*/
|
|
41
46
|
sendMessage(message: string | FormData, options?: {
|
|
42
47
|
headers?: Record<string, string>;
|
|
48
|
+
params?: Record<string, string>;
|
|
43
49
|
}): Promise<void>;
|
|
44
50
|
/**
|
|
45
51
|
* Handle streaming chunk
|
|
@@ -59,15 +65,21 @@ declare class AgnoClient extends EventEmitter {
|
|
|
59
65
|
/**
|
|
60
66
|
* Load a session
|
|
61
67
|
*/
|
|
62
|
-
loadSession(sessionId: string
|
|
68
|
+
loadSession(sessionId: string, options?: {
|
|
69
|
+
params?: Record<string, string>;
|
|
70
|
+
}): Promise<ChatMessage[]>;
|
|
63
71
|
/**
|
|
64
72
|
* Fetch all sessions
|
|
65
73
|
*/
|
|
66
|
-
fetchSessions(
|
|
74
|
+
fetchSessions(options?: {
|
|
75
|
+
params?: Record<string, string>;
|
|
76
|
+
}): Promise<SessionEntry[]>;
|
|
67
77
|
/**
|
|
68
78
|
* Delete a session
|
|
69
79
|
*/
|
|
70
|
-
deleteSession(sessionId: string
|
|
80
|
+
deleteSession(sessionId: string, options?: {
|
|
81
|
+
params?: Record<string, string>;
|
|
82
|
+
}): Promise<void>;
|
|
71
83
|
/**
|
|
72
84
|
* Add tool calls to the last message
|
|
73
85
|
* Used by frontend execution to add tool calls that were executed locally
|
|
@@ -91,33 +103,48 @@ declare class AgnoClient extends EventEmitter {
|
|
|
91
103
|
* Teams do not support the continue endpoint.
|
|
92
104
|
*
|
|
93
105
|
* @param tools - Array of tool calls with execution results
|
|
94
|
-
* @param options - Optional request headers
|
|
106
|
+
* @param options - Optional request headers and query parameters
|
|
95
107
|
* @throws Error if no paused run exists
|
|
96
108
|
* @throws Error if called with team mode (teams don't support HITL)
|
|
97
109
|
*/
|
|
98
110
|
continueRun(tools: ToolCall[], options?: {
|
|
99
111
|
headers?: Record<string, string>;
|
|
112
|
+
params?: Record<string, string>;
|
|
100
113
|
}): Promise<void>;
|
|
101
114
|
/**
|
|
102
115
|
* Check endpoint status
|
|
103
116
|
*/
|
|
104
|
-
checkStatus(
|
|
117
|
+
checkStatus(options?: {
|
|
118
|
+
params?: Record<string, string>;
|
|
119
|
+
}): Promise<boolean>;
|
|
105
120
|
/**
|
|
106
121
|
* Fetch agents from endpoint
|
|
107
122
|
*/
|
|
108
|
-
fetchAgents(
|
|
123
|
+
fetchAgents(options?: {
|
|
124
|
+
params?: Record<string, string>;
|
|
125
|
+
}): Promise<AgentDetails[]>;
|
|
109
126
|
/**
|
|
110
127
|
* Fetch teams from endpoint
|
|
111
128
|
*/
|
|
112
|
-
fetchTeams(
|
|
129
|
+
fetchTeams(options?: {
|
|
130
|
+
params?: Record<string, string>;
|
|
131
|
+
}): Promise<TeamDetails[]>;
|
|
113
132
|
/**
|
|
114
133
|
* Initialize client (check status and fetch agents/teams)
|
|
115
134
|
* Automatically selects the first available agent or team if none is configured
|
|
116
135
|
*/
|
|
117
|
-
initialize(
|
|
136
|
+
initialize(options?: {
|
|
137
|
+
params?: Record<string, string>;
|
|
138
|
+
}): Promise<{
|
|
118
139
|
agents: AgentDetails[];
|
|
119
140
|
teams: TeamDetails[];
|
|
120
141
|
}>;
|
|
142
|
+
/**
|
|
143
|
+
* Dispose of the client and clean up all resources.
|
|
144
|
+
* Call this method when the client is no longer needed to prevent memory leaks.
|
|
145
|
+
* After calling dispose(), the client instance should not be reused.
|
|
146
|
+
*/
|
|
147
|
+
dispose(): void;
|
|
121
148
|
}
|
|
122
149
|
|
|
123
150
|
/**
|