@rodrigocoliveira/agno-client 1.0.2 → 1.0.3
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/{index.d.mts → client.d.ts} +4 -47
- package/dist/client.d.ts.map +1 -0
- package/dist/index.d.ts +8 -544
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +387 -1150
- package/dist/index.js.map +22 -0
- package/dist/index.mjs +351 -1120
- package/dist/index.mjs.map +22 -0
- package/dist/managers/config-manager.d.ts +163 -0
- package/dist/managers/config-manager.d.ts.map +1 -0
- package/dist/managers/eval-manager.d.ts +27 -0
- package/dist/managers/eval-manager.d.ts.map +1 -0
- package/dist/managers/knowledge-manager.d.ts +53 -0
- package/dist/managers/knowledge-manager.d.ts.map +1 -0
- package/dist/managers/memory-manager.d.ts +39 -0
- package/dist/managers/memory-manager.d.ts.map +1 -0
- package/dist/managers/session-manager.d.ts +55 -0
- package/dist/managers/session-manager.d.ts.map +1 -0
- package/dist/managers/traces-manager.d.ts +36 -0
- package/dist/managers/traces-manager.d.ts.map +1 -0
- package/dist/parsers/stream-parser.d.ts +20 -0
- package/dist/parsers/stream-parser.d.ts.map +1 -0
- package/dist/processors/event-processor.d.ts +24 -0
- package/dist/processors/event-processor.d.ts.map +1 -0
- package/dist/stores/message-store.d.ts +44 -0
- package/dist/stores/message-store.d.ts.map +1 -0
- package/dist/utils/json-markdown.d.ts +5 -0
- package/dist/utils/json-markdown.d.ts.map +1 -0
- package/dist/utils/logger.d.ts +26 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/package.json +9 -10
- package/LICENSE +0 -21
package/dist/index.js
CHANGED
|
@@ -1,73 +1,72 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __create = Object.create;
|
|
2
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
19
|
+
var __toCommonJS = (from) => {
|
|
20
|
+
var entry = __moduleCache.get(from), desc;
|
|
21
|
+
if (entry)
|
|
22
|
+
return entry;
|
|
23
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
25
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
26
|
+
get: () => from[key],
|
|
27
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
28
|
+
}));
|
|
29
|
+
__moduleCache.set(from, entry);
|
|
30
|
+
return entry;
|
|
31
|
+
};
|
|
8
32
|
var __export = (target, all) => {
|
|
9
33
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
34
|
+
__defProp(target, name, {
|
|
35
|
+
get: all[name],
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
set: (newValue) => all[name] = () => newValue
|
|
39
|
+
});
|
|
19
40
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
41
|
|
|
30
42
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
33
|
-
|
|
43
|
+
var exports_src = {};
|
|
44
|
+
__export(exports_src, {
|
|
45
|
+
RunEvent: () => import_agno_types3.RunEvent,
|
|
34
46
|
Logger: () => Logger,
|
|
35
|
-
|
|
47
|
+
AgnoClient: () => AgnoClient
|
|
36
48
|
});
|
|
37
|
-
module.exports = __toCommonJS(
|
|
49
|
+
module.exports = __toCommonJS(exports_src);
|
|
38
50
|
|
|
39
51
|
// src/client.ts
|
|
40
52
|
var import_eventemitter3 = __toESM(require("eventemitter3"));
|
|
41
53
|
var import_agno_types2 = require("@rodrigocoliveira/agno-types");
|
|
42
54
|
|
|
43
55
|
// src/stores/message-store.ts
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this.messages = [];
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Get all messages
|
|
50
|
-
*/
|
|
56
|
+
class MessageStore {
|
|
57
|
+
messages = [];
|
|
51
58
|
getMessages() {
|
|
52
59
|
return [...this.messages];
|
|
53
60
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Set messages (replaces all)
|
|
56
|
-
*/
|
|
57
61
|
setMessages(messages) {
|
|
58
62
|
this.messages = [...messages];
|
|
59
63
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Add a message
|
|
62
|
-
*/
|
|
63
64
|
addMessage(message) {
|
|
64
65
|
this.messages = [...this.messages, message];
|
|
65
66
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Update the last message
|
|
68
|
-
*/
|
|
69
67
|
updateLastMessage(updater) {
|
|
70
|
-
if (this.messages.length === 0)
|
|
68
|
+
if (this.messages.length === 0)
|
|
69
|
+
return;
|
|
71
70
|
const lastMessage = this.messages[this.messages.length - 1];
|
|
72
71
|
const updatedMessage = updater(lastMessage);
|
|
73
72
|
this.messages = [
|
|
@@ -76,11 +75,9 @@ var MessageStore = class {
|
|
|
76
75
|
];
|
|
77
76
|
return updatedMessage;
|
|
78
77
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Update a specific message by index
|
|
81
|
-
*/
|
|
82
78
|
updateMessage(index, updater) {
|
|
83
|
-
if (index < 0 || index >= this.messages.length)
|
|
79
|
+
if (index < 0 || index >= this.messages.length)
|
|
80
|
+
return;
|
|
84
81
|
const message = this.messages[index];
|
|
85
82
|
const updatedMessage = updater(message);
|
|
86
83
|
this.messages = [
|
|
@@ -90,226 +87,123 @@ var MessageStore = class {
|
|
|
90
87
|
];
|
|
91
88
|
return updatedMessage;
|
|
92
89
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Remove last N messages
|
|
95
|
-
*/
|
|
96
90
|
removeLastMessages(count) {
|
|
97
91
|
this.messages = this.messages.slice(0, -count);
|
|
98
92
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Clear all messages
|
|
101
|
-
*/
|
|
102
93
|
clear() {
|
|
103
94
|
this.messages = [];
|
|
104
95
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Get the last message
|
|
107
|
-
*/
|
|
108
96
|
getLastMessage() {
|
|
109
|
-
return this.messages.length > 0 ? this.messages[this.messages.length - 1] :
|
|
97
|
+
return this.messages.length > 0 ? this.messages[this.messages.length - 1] : undefined;
|
|
110
98
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Check if last message has streaming error
|
|
113
|
-
*/
|
|
114
99
|
hasLastMessageError() {
|
|
115
100
|
const lastMessage = this.getLastMessage();
|
|
116
101
|
return lastMessage?.streamingError === true;
|
|
117
102
|
}
|
|
118
|
-
}
|
|
103
|
+
}
|
|
119
104
|
|
|
120
105
|
// src/managers/config-manager.ts
|
|
121
|
-
|
|
106
|
+
class ConfigManager {
|
|
107
|
+
config;
|
|
122
108
|
constructor(initialConfig) {
|
|
123
109
|
this.config = { ...initialConfig };
|
|
124
110
|
}
|
|
125
|
-
/**
|
|
126
|
-
* Get current configuration
|
|
127
|
-
*/
|
|
128
111
|
getConfig() {
|
|
129
112
|
return { ...this.config };
|
|
130
113
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Update configuration
|
|
133
|
-
*/
|
|
134
114
|
updateConfig(updates) {
|
|
135
115
|
this.config = { ...this.config, ...updates };
|
|
136
116
|
}
|
|
137
|
-
/**
|
|
138
|
-
* Helper to update a single field immutably
|
|
139
|
-
*/
|
|
140
117
|
updateField(key, value) {
|
|
141
118
|
this.config = { ...this.config, [key]: value };
|
|
142
119
|
}
|
|
143
|
-
/**
|
|
144
|
-
* Get endpoint URL
|
|
145
|
-
*/
|
|
146
120
|
getEndpoint() {
|
|
147
121
|
return this.config.endpoint;
|
|
148
122
|
}
|
|
149
|
-
/**
|
|
150
|
-
* Set endpoint URL
|
|
151
|
-
*/
|
|
152
123
|
setEndpoint(endpoint) {
|
|
153
124
|
this.updateField("endpoint", endpoint);
|
|
154
125
|
}
|
|
155
|
-
/**
|
|
156
|
-
* Get auth token
|
|
157
|
-
*/
|
|
158
126
|
getAuthToken() {
|
|
159
127
|
return this.config.authToken;
|
|
160
128
|
}
|
|
161
|
-
/**
|
|
162
|
-
* Set auth token
|
|
163
|
-
*/
|
|
164
129
|
setAuthToken(token) {
|
|
165
130
|
this.updateField("authToken", token);
|
|
166
131
|
}
|
|
167
|
-
/**
|
|
168
|
-
* Get mode (agent or team)
|
|
169
|
-
*/
|
|
170
132
|
getMode() {
|
|
171
133
|
return this.config.mode || "agent";
|
|
172
134
|
}
|
|
173
|
-
/**
|
|
174
|
-
* Set mode
|
|
175
|
-
*/
|
|
176
135
|
setMode(mode) {
|
|
177
136
|
this.updateField("mode", mode);
|
|
178
137
|
}
|
|
179
|
-
/**
|
|
180
|
-
* Get agent ID
|
|
181
|
-
*/
|
|
182
138
|
getAgentId() {
|
|
183
139
|
return this.config.agentId;
|
|
184
140
|
}
|
|
185
|
-
/**
|
|
186
|
-
* Set agent ID
|
|
187
|
-
*/
|
|
188
141
|
setAgentId(agentId) {
|
|
189
142
|
this.updateField("agentId", agentId);
|
|
190
143
|
}
|
|
191
|
-
/**
|
|
192
|
-
* Get team ID
|
|
193
|
-
*/
|
|
194
144
|
getTeamId() {
|
|
195
145
|
return this.config.teamId;
|
|
196
146
|
}
|
|
197
|
-
/**
|
|
198
|
-
* Set team ID
|
|
199
|
-
*/
|
|
200
147
|
setTeamId(teamId) {
|
|
201
148
|
this.updateField("teamId", teamId);
|
|
202
149
|
}
|
|
203
|
-
/**
|
|
204
|
-
* Get database ID
|
|
205
|
-
*/
|
|
206
150
|
getDbId() {
|
|
207
151
|
return this.config.dbId;
|
|
208
152
|
}
|
|
209
|
-
/**
|
|
210
|
-
* Set database ID
|
|
211
|
-
*/
|
|
212
153
|
setDbId(dbId) {
|
|
213
154
|
this.updateField("dbId", dbId);
|
|
214
155
|
}
|
|
215
|
-
/**
|
|
216
|
-
* Get session ID
|
|
217
|
-
*/
|
|
218
156
|
getSessionId() {
|
|
219
157
|
return this.config.sessionId;
|
|
220
158
|
}
|
|
221
|
-
/**
|
|
222
|
-
* Set session ID
|
|
223
|
-
*/
|
|
224
159
|
setSessionId(sessionId) {
|
|
225
160
|
this.updateField("sessionId", sessionId);
|
|
226
161
|
}
|
|
227
|
-
/**
|
|
228
|
-
* Get user ID
|
|
229
|
-
*/
|
|
230
162
|
getUserId() {
|
|
231
163
|
return this.config.userId;
|
|
232
164
|
}
|
|
233
|
-
/**
|
|
234
|
-
* Set user ID
|
|
235
|
-
*/
|
|
236
165
|
setUserId(userId) {
|
|
237
166
|
this.updateField("userId", userId);
|
|
238
167
|
}
|
|
239
|
-
/**
|
|
240
|
-
* Get custom headers
|
|
241
|
-
*/
|
|
242
168
|
getHeaders() {
|
|
243
169
|
return this.config.headers;
|
|
244
170
|
}
|
|
245
|
-
/**
|
|
246
|
-
* Set custom headers
|
|
247
|
-
*/
|
|
248
171
|
setHeaders(headers) {
|
|
249
172
|
this.updateField("headers", headers);
|
|
250
173
|
}
|
|
251
|
-
/**
|
|
252
|
-
* Get global query parameters
|
|
253
|
-
*/
|
|
254
174
|
getParams() {
|
|
255
175
|
return this.config.params;
|
|
256
176
|
}
|
|
257
|
-
/**
|
|
258
|
-
* Set global query parameters
|
|
259
|
-
*/
|
|
260
177
|
setParams(params) {
|
|
261
178
|
this.updateField("params", params);
|
|
262
179
|
}
|
|
263
|
-
/**
|
|
264
|
-
* Get the onTokenExpired callback
|
|
265
|
-
*/
|
|
266
180
|
getOnTokenExpired() {
|
|
267
181
|
return this.config.onTokenExpired;
|
|
268
182
|
}
|
|
269
|
-
/**
|
|
270
|
-
* Set the onTokenExpired callback
|
|
271
|
-
*/
|
|
272
183
|
setOnTokenExpired(callback) {
|
|
273
184
|
this.config.onTokenExpired = callback;
|
|
274
185
|
}
|
|
275
|
-
/**
|
|
276
|
-
* Get whether to emit member:* events for internal team activity
|
|
277
|
-
*/
|
|
278
186
|
getEmitMemberEvents() {
|
|
279
187
|
return this.config.emitMemberEvents ?? false;
|
|
280
188
|
}
|
|
281
|
-
/**
|
|
282
|
-
* Set whether to emit member:* events
|
|
283
|
-
*/
|
|
284
189
|
setEmitMemberEvents(emit) {
|
|
285
190
|
this.updateField("emitMemberEvents", emit);
|
|
286
191
|
}
|
|
287
|
-
/**
|
|
288
|
-
* Get whether to request member events from backend
|
|
289
|
-
*/
|
|
290
192
|
getStreamMemberEvents() {
|
|
291
193
|
return this.config.streamMemberEvents ?? false;
|
|
292
194
|
}
|
|
293
|
-
/**
|
|
294
|
-
* Set whether to request member events from backend
|
|
295
|
-
*/
|
|
296
195
|
setStreamMemberEvents(stream) {
|
|
297
196
|
this.updateField("streamMemberEvents", stream);
|
|
298
197
|
}
|
|
299
|
-
/**
|
|
300
|
-
* Get current entity ID (agent or team based on mode)
|
|
301
|
-
*/
|
|
302
198
|
getCurrentEntityId() {
|
|
303
199
|
return this.getMode() === "agent" ? this.getAgentId() : this.getTeamId();
|
|
304
200
|
}
|
|
305
|
-
/**
|
|
306
|
-
* Construct the run URL based on current config
|
|
307
|
-
*/
|
|
308
201
|
getRunUrl() {
|
|
309
202
|
const mode = this.getMode();
|
|
310
203
|
const endpoint = this.getEndpoint();
|
|
311
204
|
const entityId = this.getCurrentEntityId();
|
|
312
|
-
if (!entityId)
|
|
205
|
+
if (!entityId)
|
|
206
|
+
return null;
|
|
313
207
|
const encodedEntityId = encodeURIComponent(entityId);
|
|
314
208
|
if (mode === "team") {
|
|
315
209
|
return `${endpoint}/teams/${encodedEntityId}/runs`;
|
|
@@ -317,19 +211,12 @@ var ConfigManager = class {
|
|
|
317
211
|
return `${endpoint}/agents/${encodedEntityId}/runs`;
|
|
318
212
|
}
|
|
319
213
|
}
|
|
320
|
-
/**
|
|
321
|
-
* Construct the cancel URL for a specific run
|
|
322
|
-
* POST /agents/{agent_id}/runs/{run_id}/cancel
|
|
323
|
-
* POST /teams/{team_id}/runs/{run_id}/cancel
|
|
324
|
-
*
|
|
325
|
-
* @param runId - The run ID to cancel
|
|
326
|
-
* @returns The cancel URL or null if entity ID is not configured
|
|
327
|
-
*/
|
|
328
214
|
getCancelUrl(runId) {
|
|
329
215
|
const mode = this.getMode();
|
|
330
216
|
const endpoint = this.getEndpoint();
|
|
331
217
|
const entityId = this.getCurrentEntityId();
|
|
332
|
-
if (!entityId || !runId)
|
|
218
|
+
if (!entityId || !runId)
|
|
219
|
+
return null;
|
|
333
220
|
const encodedEntityId = encodeURIComponent(entityId);
|
|
334
221
|
const encodedRunId = encodeURIComponent(runId);
|
|
335
222
|
if (mode === "team") {
|
|
@@ -338,16 +225,6 @@ var ConfigManager = class {
|
|
|
338
225
|
return `${endpoint}/agents/${encodedEntityId}/runs/${encodedRunId}/cancel`;
|
|
339
226
|
}
|
|
340
227
|
}
|
|
341
|
-
/**
|
|
342
|
-
* Build request headers by merging global headers, per-request headers, and auth token.
|
|
343
|
-
* Merge order (lowest to highest precedence):
|
|
344
|
-
* 1. Global headers from config
|
|
345
|
-
* 2. Per-request headers (overrides global)
|
|
346
|
-
* 3. Authorization header from authToken (overrides all)
|
|
347
|
-
*
|
|
348
|
-
* @param perRequestHeaders - Optional headers for this specific request
|
|
349
|
-
* @returns Merged headers object ready for fetch
|
|
350
|
-
*/
|
|
351
228
|
buildRequestHeaders(perRequestHeaders) {
|
|
352
229
|
const headers = {};
|
|
353
230
|
const globalHeaders = this.getHeaders();
|
|
@@ -363,15 +240,6 @@ var ConfigManager = class {
|
|
|
363
240
|
}
|
|
364
241
|
return headers;
|
|
365
242
|
}
|
|
366
|
-
/**
|
|
367
|
-
* Build query string by merging global params and per-request params.
|
|
368
|
-
* Merge order (lowest to highest precedence):
|
|
369
|
-
* 1. Global params from config
|
|
370
|
-
* 2. Per-request params (overrides global)
|
|
371
|
-
*
|
|
372
|
-
* @param perRequestParams - Optional query parameters for this specific request
|
|
373
|
-
* @returns URLSearchParams object ready to append to URLs
|
|
374
|
-
*/
|
|
375
243
|
buildQueryString(perRequestParams) {
|
|
376
244
|
const params = {};
|
|
377
245
|
const globalParams = this.getParams();
|
|
@@ -383,13 +251,10 @@ var ConfigManager = class {
|
|
|
383
251
|
}
|
|
384
252
|
return new URLSearchParams(params);
|
|
385
253
|
}
|
|
386
|
-
}
|
|
254
|
+
}
|
|
387
255
|
|
|
388
256
|
// src/managers/session-manager.ts
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Fetch all sessions for an entity
|
|
392
|
-
*/
|
|
257
|
+
class SessionManager {
|
|
393
258
|
async fetchSessions(endpoint, entityType, entityId, dbId, headers, params) {
|
|
394
259
|
const url = new URL(`${endpoint}/sessions`);
|
|
395
260
|
url.searchParams.set("type", entityType);
|
|
@@ -410,10 +275,6 @@ var SessionManager = class {
|
|
|
410
275
|
const data = await response.json();
|
|
411
276
|
return data.data ?? [];
|
|
412
277
|
}
|
|
413
|
-
/**
|
|
414
|
-
* Fetch a specific session's runs
|
|
415
|
-
* Returns an array of RunSchema directly (not wrapped in { data, meta })
|
|
416
|
-
*/
|
|
417
278
|
async fetchSession(endpoint, entityType, sessionId, dbId, headers, userId, params) {
|
|
418
279
|
const url = new URL(`${endpoint}/sessions/${sessionId}/runs`);
|
|
419
280
|
url.searchParams.set("type", entityType);
|
|
@@ -434,9 +295,6 @@ var SessionManager = class {
|
|
|
434
295
|
}
|
|
435
296
|
return await response.json();
|
|
436
297
|
}
|
|
437
|
-
/**
|
|
438
|
-
* Delete a session
|
|
439
|
-
*/
|
|
440
298
|
async deleteSession(endpoint, sessionId, dbId, headers, params) {
|
|
441
299
|
const url = new URL(`${endpoint}/sessions/${sessionId}`);
|
|
442
300
|
if (dbId) {
|
|
@@ -455,9 +313,6 @@ var SessionManager = class {
|
|
|
455
313
|
throw new Error(`Failed to delete session: ${response.statusText}`);
|
|
456
314
|
}
|
|
457
315
|
}
|
|
458
|
-
/**
|
|
459
|
-
* Get a session by ID
|
|
460
|
-
*/
|
|
461
316
|
async getSessionById(endpoint, entityType, sessionId, dbId, headers, userId, params) {
|
|
462
317
|
const url = new URL(`${endpoint}/sessions/${sessionId}`);
|
|
463
318
|
url.searchParams.set("type", entityType);
|
|
@@ -478,9 +333,6 @@ var SessionManager = class {
|
|
|
478
333
|
}
|
|
479
334
|
return await response.json();
|
|
480
335
|
}
|
|
481
|
-
/**
|
|
482
|
-
* Get a run by ID
|
|
483
|
-
*/
|
|
484
336
|
async getRunById(endpoint, entityType, sessionId, runId, dbId, headers, userId, params) {
|
|
485
337
|
const url = new URL(`${endpoint}/sessions/${sessionId}/runs/${runId}`);
|
|
486
338
|
url.searchParams.set("type", entityType);
|
|
@@ -501,9 +353,6 @@ var SessionManager = class {
|
|
|
501
353
|
}
|
|
502
354
|
return await response.json();
|
|
503
355
|
}
|
|
504
|
-
/**
|
|
505
|
-
* Create a new session
|
|
506
|
-
*/
|
|
507
356
|
async createSession(endpoint, entityType, request, dbId, headers, params) {
|
|
508
357
|
const url = new URL(`${endpoint}/sessions`);
|
|
509
358
|
url.searchParams.set("type", entityType);
|
|
@@ -528,9 +377,6 @@ var SessionManager = class {
|
|
|
528
377
|
}
|
|
529
378
|
return await response.json();
|
|
530
379
|
}
|
|
531
|
-
/**
|
|
532
|
-
* Update a session
|
|
533
|
-
*/
|
|
534
380
|
async updateSession(endpoint, entityType, sessionId, request, dbId, headers, userId, params) {
|
|
535
381
|
const url = new URL(`${endpoint}/sessions/${sessionId}`);
|
|
536
382
|
url.searchParams.set("type", entityType);
|
|
@@ -558,9 +404,6 @@ var SessionManager = class {
|
|
|
558
404
|
}
|
|
559
405
|
return await response.json();
|
|
560
406
|
}
|
|
561
|
-
/**
|
|
562
|
-
* Rename a session
|
|
563
|
-
*/
|
|
564
407
|
async renameSession(endpoint, entityType, sessionId, newName, dbId, headers, params) {
|
|
565
408
|
const url = new URL(`${endpoint}/sessions/${sessionId}/rename`);
|
|
566
409
|
url.searchParams.set("type", entityType);
|
|
@@ -585,9 +428,6 @@ var SessionManager = class {
|
|
|
585
428
|
}
|
|
586
429
|
return await response.json();
|
|
587
430
|
}
|
|
588
|
-
/**
|
|
589
|
-
* Delete multiple sessions
|
|
590
|
-
*/
|
|
591
431
|
async deleteMultipleSessions(endpoint, sessionIds, sessionTypes, dbId, headers, params) {
|
|
592
432
|
const url = new URL(`${endpoint}/sessions`);
|
|
593
433
|
if (dbId) {
|
|
@@ -613,24 +453,15 @@ var SessionManager = class {
|
|
|
613
453
|
throw new Error(`Failed to delete sessions: ${response.statusText}`);
|
|
614
454
|
}
|
|
615
455
|
}
|
|
616
|
-
/**
|
|
617
|
-
* Convert session runs array to chat messages.
|
|
618
|
-
* Filters out child runs (those with parent_run_id) to prevent
|
|
619
|
-
* internal team member communications from appearing as user messages.
|
|
620
|
-
*/
|
|
621
456
|
convertSessionToMessages(runs) {
|
|
622
457
|
const rootRuns = runs.filter((run) => !run.parent_run_id);
|
|
623
458
|
const messages = this.convertRunsToMessages(rootRuns);
|
|
624
459
|
return messages;
|
|
625
460
|
}
|
|
626
|
-
/**
|
|
627
|
-
* Convert RunSchema[] to ChatMessage[]
|
|
628
|
-
* Each run represents a user input + agent response pair
|
|
629
|
-
*/
|
|
630
461
|
convertRunsToMessages(runs) {
|
|
631
462
|
const messages = [];
|
|
632
463
|
for (const run of runs) {
|
|
633
|
-
const timestamp = run.created_at ? new Date(run.created_at).getTime() /
|
|
464
|
+
const timestamp = run.created_at ? new Date(run.created_at).getTime() / 1000 : Math.floor(Date.now() / 1000);
|
|
634
465
|
if (run.run_input) {
|
|
635
466
|
const userImages = [];
|
|
636
467
|
const userAudio = [];
|
|
@@ -664,7 +495,7 @@ var SessionManager = class {
|
|
|
664
495
|
if (url) {
|
|
665
496
|
userAudio.push({
|
|
666
497
|
url,
|
|
667
|
-
mime_type: audObj.mime_type ||
|
|
498
|
+
mime_type: audObj.mime_type || undefined
|
|
668
499
|
});
|
|
669
500
|
}
|
|
670
501
|
}
|
|
@@ -681,7 +512,7 @@ var SessionManager = class {
|
|
|
681
512
|
name: fileObj.original_name || fileObj.name || "file",
|
|
682
513
|
type: fileObj.content_type || fileObj.mime_type || "",
|
|
683
514
|
url,
|
|
684
|
-
size: fileObj.size ||
|
|
515
|
+
size: fileObj.size || undefined
|
|
685
516
|
});
|
|
686
517
|
}
|
|
687
518
|
}
|
|
@@ -739,42 +570,48 @@ var SessionManager = class {
|
|
|
739
570
|
reasoning_messages: run.reasoning_messages,
|
|
740
571
|
reasoning_steps: run.reasoning_steps,
|
|
741
572
|
references: run.references
|
|
742
|
-
} :
|
|
573
|
+
} : undefined;
|
|
743
574
|
messages.push({
|
|
744
575
|
role: "agent",
|
|
745
576
|
content: contentStr,
|
|
746
|
-
tool_calls: toolCalls.length > 0 ? toolCalls :
|
|
577
|
+
tool_calls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
747
578
|
extra_data: extraData,
|
|
748
579
|
images: run.images,
|
|
749
580
|
videos: run.videos,
|
|
750
581
|
audio: run.audio,
|
|
751
582
|
response_audio: run.response_audio,
|
|
752
583
|
created_at: timestamp + 1
|
|
753
|
-
// Agent response is slightly after user message
|
|
754
584
|
});
|
|
755
585
|
}
|
|
756
586
|
return messages;
|
|
757
587
|
}
|
|
758
|
-
}
|
|
588
|
+
}
|
|
759
589
|
|
|
760
590
|
// src/managers/memory-manager.ts
|
|
761
|
-
|
|
762
|
-
/**
|
|
763
|
-
* Fetch memories with filtering and pagination
|
|
764
|
-
*/
|
|
591
|
+
class MemoryManager {
|
|
765
592
|
async fetchMemories(endpoint, dbId, headers, queryParams, params) {
|
|
766
593
|
const url = new URL(`${endpoint}/memories`);
|
|
767
594
|
if (queryParams) {
|
|
768
|
-
if (queryParams.user_id)
|
|
769
|
-
|
|
770
|
-
if (queryParams.
|
|
771
|
-
|
|
772
|
-
if (queryParams.
|
|
773
|
-
|
|
774
|
-
if (queryParams.
|
|
775
|
-
|
|
776
|
-
if (queryParams.
|
|
777
|
-
|
|
595
|
+
if (queryParams.user_id)
|
|
596
|
+
url.searchParams.set("user_id", queryParams.user_id);
|
|
597
|
+
if (queryParams.agent_id)
|
|
598
|
+
url.searchParams.set("agent_id", queryParams.agent_id);
|
|
599
|
+
if (queryParams.team_id)
|
|
600
|
+
url.searchParams.set("team_id", queryParams.team_id);
|
|
601
|
+
if (queryParams.search_content)
|
|
602
|
+
url.searchParams.set("search_content", queryParams.search_content);
|
|
603
|
+
if (queryParams.limit !== undefined)
|
|
604
|
+
url.searchParams.set("limit", String(queryParams.limit));
|
|
605
|
+
if (queryParams.page !== undefined)
|
|
606
|
+
url.searchParams.set("page", String(queryParams.page));
|
|
607
|
+
if (queryParams.sort_by)
|
|
608
|
+
url.searchParams.set("sort_by", queryParams.sort_by);
|
|
609
|
+
if (queryParams.sort_order)
|
|
610
|
+
url.searchParams.set("sort_order", queryParams.sort_order);
|
|
611
|
+
if (queryParams.db_id)
|
|
612
|
+
url.searchParams.set("db_id", queryParams.db_id);
|
|
613
|
+
if (queryParams.table)
|
|
614
|
+
url.searchParams.set("table", queryParams.table);
|
|
778
615
|
if (queryParams.topics && queryParams.topics.length > 0) {
|
|
779
616
|
url.searchParams.set("topics", queryParams.topics.join(","));
|
|
780
617
|
}
|
|
@@ -796,14 +633,14 @@ var MemoryManager = class {
|
|
|
796
633
|
}
|
|
797
634
|
return await response.json();
|
|
798
635
|
}
|
|
799
|
-
/**
|
|
800
|
-
* Get a specific memory by ID
|
|
801
|
-
*/
|
|
802
636
|
async getMemoryById(endpoint, memoryId, dbId, headers, userId, table, params) {
|
|
803
637
|
const url = new URL(`${endpoint}/memories/${memoryId}`);
|
|
804
|
-
if (userId)
|
|
805
|
-
|
|
806
|
-
if (
|
|
638
|
+
if (userId)
|
|
639
|
+
url.searchParams.set("user_id", userId);
|
|
640
|
+
if (dbId)
|
|
641
|
+
url.searchParams.set("db_id", dbId);
|
|
642
|
+
if (table)
|
|
643
|
+
url.searchParams.set("table", table);
|
|
807
644
|
if (params) {
|
|
808
645
|
params.forEach((value, key) => {
|
|
809
646
|
url.searchParams.set(key, value);
|
|
@@ -815,13 +652,12 @@ var MemoryManager = class {
|
|
|
815
652
|
}
|
|
816
653
|
return await response.json();
|
|
817
654
|
}
|
|
818
|
-
/**
|
|
819
|
-
* Get all available memory topics
|
|
820
|
-
*/
|
|
821
655
|
async getMemoryTopics(endpoint, dbId, headers, table, params) {
|
|
822
656
|
const url = new URL(`${endpoint}/memory_topics`);
|
|
823
|
-
if (dbId)
|
|
824
|
-
|
|
657
|
+
if (dbId)
|
|
658
|
+
url.searchParams.set("db_id", dbId);
|
|
659
|
+
if (table)
|
|
660
|
+
url.searchParams.set("table", table);
|
|
825
661
|
if (params) {
|
|
826
662
|
params.forEach((value, key) => {
|
|
827
663
|
url.searchParams.set(key, value);
|
|
@@ -836,16 +672,17 @@ var MemoryManager = class {
|
|
|
836
672
|
}
|
|
837
673
|
return await response.json();
|
|
838
674
|
}
|
|
839
|
-
/**
|
|
840
|
-
* Get user memory statistics
|
|
841
|
-
*/
|
|
842
675
|
async getUserMemoryStats(endpoint, dbId, headers, queryParams, params) {
|
|
843
676
|
const url = new URL(`${endpoint}/user_memory_stats`);
|
|
844
677
|
if (queryParams) {
|
|
845
|
-
if (queryParams.limit !==
|
|
846
|
-
|
|
847
|
-
if (queryParams.
|
|
848
|
-
|
|
678
|
+
if (queryParams.limit !== undefined)
|
|
679
|
+
url.searchParams.set("limit", String(queryParams.limit));
|
|
680
|
+
if (queryParams.page !== undefined)
|
|
681
|
+
url.searchParams.set("page", String(queryParams.page));
|
|
682
|
+
if (queryParams.db_id)
|
|
683
|
+
url.searchParams.set("db_id", queryParams.db_id);
|
|
684
|
+
if (queryParams.table)
|
|
685
|
+
url.searchParams.set("table", queryParams.table);
|
|
849
686
|
}
|
|
850
687
|
if (!queryParams?.db_id && dbId) {
|
|
851
688
|
url.searchParams.set("db_id", dbId);
|
|
@@ -864,13 +701,12 @@ var MemoryManager = class {
|
|
|
864
701
|
}
|
|
865
702
|
return await response.json();
|
|
866
703
|
}
|
|
867
|
-
/**
|
|
868
|
-
* Create a new memory
|
|
869
|
-
*/
|
|
870
704
|
async createMemory(endpoint, request, dbId, headers, table, params) {
|
|
871
705
|
const url = new URL(`${endpoint}/memories`);
|
|
872
|
-
if (dbId)
|
|
873
|
-
|
|
706
|
+
if (dbId)
|
|
707
|
+
url.searchParams.set("db_id", dbId);
|
|
708
|
+
if (table)
|
|
709
|
+
url.searchParams.set("table", table);
|
|
874
710
|
if (params) {
|
|
875
711
|
params.forEach((value, key) => {
|
|
876
712
|
url.searchParams.set(key, value);
|
|
@@ -889,13 +725,12 @@ var MemoryManager = class {
|
|
|
889
725
|
}
|
|
890
726
|
return await response.json();
|
|
891
727
|
}
|
|
892
|
-
/**
|
|
893
|
-
* Update an existing memory
|
|
894
|
-
*/
|
|
895
728
|
async updateMemory(endpoint, memoryId, request, dbId, headers, table, params) {
|
|
896
729
|
const url = new URL(`${endpoint}/memories/${memoryId}`);
|
|
897
|
-
if (dbId)
|
|
898
|
-
|
|
730
|
+
if (dbId)
|
|
731
|
+
url.searchParams.set("db_id", dbId);
|
|
732
|
+
if (table)
|
|
733
|
+
url.searchParams.set("table", table);
|
|
899
734
|
if (params) {
|
|
900
735
|
params.forEach((value, key) => {
|
|
901
736
|
url.searchParams.set(key, value);
|
|
@@ -914,14 +749,14 @@ var MemoryManager = class {
|
|
|
914
749
|
}
|
|
915
750
|
return await response.json();
|
|
916
751
|
}
|
|
917
|
-
/**
|
|
918
|
-
* Delete a single memory
|
|
919
|
-
*/
|
|
920
752
|
async deleteMemory(endpoint, memoryId, dbId, headers, userId, table, params) {
|
|
921
753
|
const url = new URL(`${endpoint}/memories/${memoryId}`);
|
|
922
|
-
if (userId)
|
|
923
|
-
|
|
924
|
-
if (
|
|
754
|
+
if (userId)
|
|
755
|
+
url.searchParams.set("user_id", userId);
|
|
756
|
+
if (dbId)
|
|
757
|
+
url.searchParams.set("db_id", dbId);
|
|
758
|
+
if (table)
|
|
759
|
+
url.searchParams.set("table", table);
|
|
925
760
|
if (params) {
|
|
926
761
|
params.forEach((value, key) => {
|
|
927
762
|
url.searchParams.set(key, value);
|
|
@@ -935,13 +770,12 @@ var MemoryManager = class {
|
|
|
935
770
|
throw new Error(`Failed to delete memory: ${response.statusText}`);
|
|
936
771
|
}
|
|
937
772
|
}
|
|
938
|
-
/**
|
|
939
|
-
* Delete multiple memories
|
|
940
|
-
*/
|
|
941
773
|
async deleteMultipleMemories(endpoint, request, dbId, headers, table, params) {
|
|
942
774
|
const url = new URL(`${endpoint}/memories`);
|
|
943
|
-
if (dbId)
|
|
944
|
-
|
|
775
|
+
if (dbId)
|
|
776
|
+
url.searchParams.set("db_id", dbId);
|
|
777
|
+
if (table)
|
|
778
|
+
url.searchParams.set("table", table);
|
|
945
779
|
if (params) {
|
|
946
780
|
params.forEach((value, key) => {
|
|
947
781
|
url.searchParams.set(key, value);
|
|
@@ -959,14 +793,10 @@ var MemoryManager = class {
|
|
|
959
793
|
throw new Error(`Failed to delete memories: ${response.statusText}`);
|
|
960
794
|
}
|
|
961
795
|
}
|
|
962
|
-
}
|
|
796
|
+
}
|
|
963
797
|
|
|
964
798
|
// src/managers/knowledge-manager.ts
|
|
965
|
-
|
|
966
|
-
/**
|
|
967
|
-
* Get knowledge configuration
|
|
968
|
-
* GET /knowledge/config
|
|
969
|
-
*/
|
|
799
|
+
class KnowledgeManager {
|
|
970
800
|
async getConfig(endpoint, headers, dbId, params) {
|
|
971
801
|
const url = new URL(`${endpoint}/knowledge/config`);
|
|
972
802
|
if (dbId) {
|
|
@@ -983,16 +813,12 @@ var KnowledgeManager = class {
|
|
|
983
813
|
}
|
|
984
814
|
return await response.json();
|
|
985
815
|
}
|
|
986
|
-
/**
|
|
987
|
-
* List all content
|
|
988
|
-
* GET /knowledge/content
|
|
989
|
-
*/
|
|
990
816
|
async listContent(endpoint, headers, options, params) {
|
|
991
817
|
const url = new URL(`${endpoint}/knowledge/content`);
|
|
992
|
-
if (options?.limit !==
|
|
818
|
+
if (options?.limit !== undefined) {
|
|
993
819
|
url.searchParams.set("limit", String(options.limit));
|
|
994
820
|
}
|
|
995
|
-
if (options?.page !==
|
|
821
|
+
if (options?.page !== undefined) {
|
|
996
822
|
url.searchParams.set("page", String(options.page));
|
|
997
823
|
}
|
|
998
824
|
if (options?.sort_by) {
|
|
@@ -1015,14 +841,8 @@ var KnowledgeManager = class {
|
|
|
1015
841
|
}
|
|
1016
842
|
return await response.json();
|
|
1017
843
|
}
|
|
1018
|
-
/**
|
|
1019
|
-
* Get content by ID
|
|
1020
|
-
* GET /knowledge/content/{content_id}
|
|
1021
|
-
*/
|
|
1022
844
|
async getContent(endpoint, contentId, headers, dbId, params) {
|
|
1023
|
-
const url = new URL(
|
|
1024
|
-
`${endpoint}/knowledge/content/${encodeURIComponent(contentId)}`
|
|
1025
|
-
);
|
|
845
|
+
const url = new URL(`${endpoint}/knowledge/content/${encodeURIComponent(contentId)}`);
|
|
1026
846
|
if (dbId) {
|
|
1027
847
|
url.searchParams.set("db_id", dbId);
|
|
1028
848
|
}
|
|
@@ -1037,14 +857,8 @@ var KnowledgeManager = class {
|
|
|
1037
857
|
}
|
|
1038
858
|
return await response.json();
|
|
1039
859
|
}
|
|
1040
|
-
/**
|
|
1041
|
-
* Get content status
|
|
1042
|
-
* GET /knowledge/content/{content_id}/status
|
|
1043
|
-
*/
|
|
1044
860
|
async getContentStatus(endpoint, contentId, headers, dbId, params) {
|
|
1045
|
-
const url = new URL(
|
|
1046
|
-
`${endpoint}/knowledge/content/${encodeURIComponent(contentId)}/status`
|
|
1047
|
-
);
|
|
861
|
+
const url = new URL(`${endpoint}/knowledge/content/${encodeURIComponent(contentId)}/status`);
|
|
1048
862
|
if (dbId) {
|
|
1049
863
|
url.searchParams.set("db_id", dbId);
|
|
1050
864
|
}
|
|
@@ -1059,10 +873,6 @@ var KnowledgeManager = class {
|
|
|
1059
873
|
}
|
|
1060
874
|
return await response.json();
|
|
1061
875
|
}
|
|
1062
|
-
/**
|
|
1063
|
-
* Search knowledge base
|
|
1064
|
-
* POST /knowledge/search
|
|
1065
|
-
*/
|
|
1066
876
|
async search(endpoint, request, headers, params) {
|
|
1067
877
|
const url = new URL(`${endpoint}/knowledge/search`);
|
|
1068
878
|
if (params) {
|
|
@@ -1083,11 +893,6 @@ var KnowledgeManager = class {
|
|
|
1083
893
|
}
|
|
1084
894
|
return await response.json();
|
|
1085
895
|
}
|
|
1086
|
-
/**
|
|
1087
|
-
* Upload content
|
|
1088
|
-
* POST /knowledge/content
|
|
1089
|
-
* Returns 202 Accepted - content is processed asynchronously
|
|
1090
|
-
*/
|
|
1091
896
|
async uploadContent(endpoint, formData, headers, dbId, params) {
|
|
1092
897
|
const url = new URL(`${endpoint}/knowledge/content`);
|
|
1093
898
|
if (dbId) {
|
|
@@ -1109,14 +914,8 @@ var KnowledgeManager = class {
|
|
|
1109
914
|
}
|
|
1110
915
|
return await response.json();
|
|
1111
916
|
}
|
|
1112
|
-
/**
|
|
1113
|
-
* Update content
|
|
1114
|
-
* PATCH /knowledge/content/{content_id}
|
|
1115
|
-
*/
|
|
1116
917
|
async updateContent(endpoint, contentId, request, headers, dbId, params) {
|
|
1117
|
-
const url = new URL(
|
|
1118
|
-
`${endpoint}/knowledge/content/${encodeURIComponent(contentId)}`
|
|
1119
|
-
);
|
|
918
|
+
const url = new URL(`${endpoint}/knowledge/content/${encodeURIComponent(contentId)}`);
|
|
1120
919
|
if (dbId) {
|
|
1121
920
|
url.searchParams.set("db_id", dbId);
|
|
1122
921
|
}
|
|
@@ -1125,17 +924,17 @@ var KnowledgeManager = class {
|
|
|
1125
924
|
url.searchParams.set(key, value);
|
|
1126
925
|
});
|
|
1127
926
|
}
|
|
1128
|
-
const formBody = new URLSearchParams
|
|
1129
|
-
if (request.name !==
|
|
927
|
+
const formBody = new URLSearchParams;
|
|
928
|
+
if (request.name !== undefined && request.name !== null) {
|
|
1130
929
|
formBody.set("name", request.name);
|
|
1131
930
|
}
|
|
1132
|
-
if (request.description !==
|
|
931
|
+
if (request.description !== undefined && request.description !== null) {
|
|
1133
932
|
formBody.set("description", request.description);
|
|
1134
933
|
}
|
|
1135
|
-
if (request.metadata !==
|
|
934
|
+
if (request.metadata !== undefined && request.metadata !== null) {
|
|
1136
935
|
formBody.set("metadata", request.metadata);
|
|
1137
936
|
}
|
|
1138
|
-
if (request.reader_id !==
|
|
937
|
+
if (request.reader_id !== undefined && request.reader_id !== null) {
|
|
1139
938
|
formBody.set("reader_id", request.reader_id);
|
|
1140
939
|
}
|
|
1141
940
|
const response = await fetch(url.toString(), {
|
|
@@ -1151,10 +950,6 @@ var KnowledgeManager = class {
|
|
|
1151
950
|
}
|
|
1152
951
|
return await response.json();
|
|
1153
952
|
}
|
|
1154
|
-
/**
|
|
1155
|
-
* Delete all content
|
|
1156
|
-
* DELETE /knowledge/content
|
|
1157
|
-
*/
|
|
1158
953
|
async deleteAllContent(endpoint, headers, dbId, params) {
|
|
1159
954
|
const url = new URL(`${endpoint}/knowledge/content`);
|
|
1160
955
|
if (dbId) {
|
|
@@ -1173,14 +968,8 @@ var KnowledgeManager = class {
|
|
|
1173
968
|
throw new Error(`Failed to delete all content: ${response.statusText}`);
|
|
1174
969
|
}
|
|
1175
970
|
}
|
|
1176
|
-
/**
|
|
1177
|
-
* Delete content by ID
|
|
1178
|
-
* DELETE /knowledge/content/{content_id}
|
|
1179
|
-
*/
|
|
1180
971
|
async deleteContent(endpoint, contentId, headers, dbId, params) {
|
|
1181
|
-
const url = new URL(
|
|
1182
|
-
`${endpoint}/knowledge/content/${encodeURIComponent(contentId)}`
|
|
1183
|
-
);
|
|
972
|
+
const url = new URL(`${endpoint}/knowledge/content/${encodeURIComponent(contentId)}`);
|
|
1184
973
|
if (dbId) {
|
|
1185
974
|
url.searchParams.set("db_id", dbId);
|
|
1186
975
|
}
|
|
@@ -1198,27 +987,36 @@ var KnowledgeManager = class {
|
|
|
1198
987
|
}
|
|
1199
988
|
return await response.json();
|
|
1200
989
|
}
|
|
1201
|
-
}
|
|
990
|
+
}
|
|
1202
991
|
|
|
1203
992
|
// src/managers/eval-manager.ts
|
|
1204
|
-
|
|
1205
|
-
/**
|
|
1206
|
-
* List evaluation runs with optional filtering and pagination
|
|
1207
|
-
*/
|
|
993
|
+
class EvalManager {
|
|
1208
994
|
async listEvalRuns(endpoint, listParams, headers, additionalParams) {
|
|
1209
995
|
const url = new URL(`${endpoint}/eval-runs`);
|
|
1210
|
-
if (listParams.agent_id)
|
|
1211
|
-
|
|
1212
|
-
if (listParams.
|
|
1213
|
-
|
|
1214
|
-
if (listParams.
|
|
1215
|
-
|
|
1216
|
-
if (listParams.
|
|
1217
|
-
|
|
1218
|
-
if (listParams.
|
|
1219
|
-
|
|
1220
|
-
if (listParams.
|
|
1221
|
-
|
|
996
|
+
if (listParams.agent_id)
|
|
997
|
+
url.searchParams.set("agent_id", listParams.agent_id);
|
|
998
|
+
if (listParams.team_id)
|
|
999
|
+
url.searchParams.set("team_id", listParams.team_id);
|
|
1000
|
+
if (listParams.workflow_id)
|
|
1001
|
+
url.searchParams.set("workflow_id", listParams.workflow_id);
|
|
1002
|
+
if (listParams.model_id)
|
|
1003
|
+
url.searchParams.set("model_id", listParams.model_id);
|
|
1004
|
+
if (listParams.type)
|
|
1005
|
+
url.searchParams.set("type", listParams.type);
|
|
1006
|
+
if (listParams.limit !== undefined)
|
|
1007
|
+
url.searchParams.set("limit", String(listParams.limit));
|
|
1008
|
+
if (listParams.page !== undefined)
|
|
1009
|
+
url.searchParams.set("page", String(listParams.page));
|
|
1010
|
+
if (listParams.sort_by)
|
|
1011
|
+
url.searchParams.set("sort_by", listParams.sort_by);
|
|
1012
|
+
if (listParams.sort_order)
|
|
1013
|
+
url.searchParams.set("sort_order", listParams.sort_order);
|
|
1014
|
+
if (listParams.db_id)
|
|
1015
|
+
url.searchParams.set("db_id", listParams.db_id);
|
|
1016
|
+
if (listParams.table)
|
|
1017
|
+
url.searchParams.set("table", listParams.table);
|
|
1018
|
+
if (listParams.eval_types)
|
|
1019
|
+
url.searchParams.set("eval_types", listParams.eval_types);
|
|
1222
1020
|
if (additionalParams) {
|
|
1223
1021
|
additionalParams.forEach((value, key) => {
|
|
1224
1022
|
url.searchParams.set(key, value);
|
|
@@ -1233,13 +1031,12 @@ var EvalManager = class {
|
|
|
1233
1031
|
}
|
|
1234
1032
|
return await response.json();
|
|
1235
1033
|
}
|
|
1236
|
-
/**
|
|
1237
|
-
* Get a specific evaluation run by ID
|
|
1238
|
-
*/
|
|
1239
1034
|
async getEvalRun(endpoint, evalRunId, dbId, table, headers, additionalParams) {
|
|
1240
1035
|
const url = new URL(`${endpoint}/eval-runs/${encodeURIComponent(evalRunId)}`);
|
|
1241
|
-
if (dbId)
|
|
1242
|
-
|
|
1036
|
+
if (dbId)
|
|
1037
|
+
url.searchParams.set("db_id", dbId);
|
|
1038
|
+
if (table)
|
|
1039
|
+
url.searchParams.set("table", table);
|
|
1243
1040
|
if (additionalParams) {
|
|
1244
1041
|
additionalParams.forEach((value, key) => {
|
|
1245
1042
|
url.searchParams.set(key, value);
|
|
@@ -1251,13 +1048,12 @@ var EvalManager = class {
|
|
|
1251
1048
|
}
|
|
1252
1049
|
return await response.json();
|
|
1253
1050
|
}
|
|
1254
|
-
/**
|
|
1255
|
-
* Execute a new evaluation
|
|
1256
|
-
*/
|
|
1257
1051
|
async executeEval(endpoint, request, dbId, table, headers, additionalParams) {
|
|
1258
1052
|
const url = new URL(`${endpoint}/eval-runs`);
|
|
1259
|
-
if (dbId)
|
|
1260
|
-
|
|
1053
|
+
if (dbId)
|
|
1054
|
+
url.searchParams.set("db_id", dbId);
|
|
1055
|
+
if (table)
|
|
1056
|
+
url.searchParams.set("table", table);
|
|
1261
1057
|
if (additionalParams) {
|
|
1262
1058
|
additionalParams.forEach((value, key) => {
|
|
1263
1059
|
url.searchParams.set(key, value);
|
|
@@ -1277,13 +1073,12 @@ var EvalManager = class {
|
|
|
1277
1073
|
}
|
|
1278
1074
|
return await response.json();
|
|
1279
1075
|
}
|
|
1280
|
-
/**
|
|
1281
|
-
* Update an evaluation run (rename)
|
|
1282
|
-
*/
|
|
1283
1076
|
async updateEvalRun(endpoint, evalRunId, request, dbId, table, headers, additionalParams) {
|
|
1284
1077
|
const url = new URL(`${endpoint}/eval-runs/${encodeURIComponent(evalRunId)}`);
|
|
1285
|
-
if (dbId)
|
|
1286
|
-
|
|
1078
|
+
if (dbId)
|
|
1079
|
+
url.searchParams.set("db_id", dbId);
|
|
1080
|
+
if (table)
|
|
1081
|
+
url.searchParams.set("table", table);
|
|
1287
1082
|
if (additionalParams) {
|
|
1288
1083
|
additionalParams.forEach((value, key) => {
|
|
1289
1084
|
url.searchParams.set(key, value);
|
|
@@ -1302,13 +1097,12 @@ var EvalManager = class {
|
|
|
1302
1097
|
}
|
|
1303
1098
|
return await response.json();
|
|
1304
1099
|
}
|
|
1305
|
-
/**
|
|
1306
|
-
* Delete multiple evaluation runs
|
|
1307
|
-
*/
|
|
1308
1100
|
async deleteEvalRuns(endpoint, request, dbId, table, headers, additionalParams) {
|
|
1309
1101
|
const url = new URL(`${endpoint}/eval-runs`);
|
|
1310
|
-
if (dbId)
|
|
1311
|
-
|
|
1102
|
+
if (dbId)
|
|
1103
|
+
url.searchParams.set("db_id", dbId);
|
|
1104
|
+
if (table)
|
|
1105
|
+
url.searchParams.set("table", table);
|
|
1312
1106
|
if (additionalParams) {
|
|
1313
1107
|
additionalParams.forEach((value, key) => {
|
|
1314
1108
|
url.searchParams.set(key, value);
|
|
@@ -1326,28 +1120,36 @@ var EvalManager = class {
|
|
|
1326
1120
|
throw new Error(`Failed to delete evaluation runs: ${response.statusText}`);
|
|
1327
1121
|
}
|
|
1328
1122
|
}
|
|
1329
|
-
}
|
|
1123
|
+
}
|
|
1330
1124
|
|
|
1331
1125
|
// src/managers/traces-manager.ts
|
|
1332
|
-
|
|
1333
|
-
/**
|
|
1334
|
-
* Fetch traces with optional filters
|
|
1335
|
-
* GET /traces
|
|
1336
|
-
*/
|
|
1126
|
+
class TracesManager {
|
|
1337
1127
|
async fetchTraces(endpoint, options, headers, params) {
|
|
1338
1128
|
const url = new URL(`${endpoint}/traces`);
|
|
1339
|
-
if (options.run_id)
|
|
1340
|
-
|
|
1341
|
-
if (options.
|
|
1342
|
-
|
|
1343
|
-
if (options.
|
|
1344
|
-
|
|
1345
|
-
if (options.
|
|
1346
|
-
|
|
1347
|
-
if (options.
|
|
1348
|
-
|
|
1349
|
-
if (options.
|
|
1350
|
-
|
|
1129
|
+
if (options.run_id)
|
|
1130
|
+
url.searchParams.set("run_id", options.run_id);
|
|
1131
|
+
if (options.session_id)
|
|
1132
|
+
url.searchParams.set("session_id", options.session_id);
|
|
1133
|
+
if (options.user_id)
|
|
1134
|
+
url.searchParams.set("user_id", options.user_id);
|
|
1135
|
+
if (options.agent_id)
|
|
1136
|
+
url.searchParams.set("agent_id", options.agent_id);
|
|
1137
|
+
if (options.team_id)
|
|
1138
|
+
url.searchParams.set("team_id", options.team_id);
|
|
1139
|
+
if (options.workflow_id)
|
|
1140
|
+
url.searchParams.set("workflow_id", options.workflow_id);
|
|
1141
|
+
if (options.status)
|
|
1142
|
+
url.searchParams.set("status", options.status);
|
|
1143
|
+
if (options.start_time)
|
|
1144
|
+
url.searchParams.set("start_time", options.start_time);
|
|
1145
|
+
if (options.end_time)
|
|
1146
|
+
url.searchParams.set("end_time", options.end_time);
|
|
1147
|
+
if (options.page !== undefined)
|
|
1148
|
+
url.searchParams.set("page", String(options.page));
|
|
1149
|
+
if (options.limit !== undefined)
|
|
1150
|
+
url.searchParams.set("limit", String(options.limit));
|
|
1151
|
+
if (options.db_id)
|
|
1152
|
+
url.searchParams.set("db_id", options.db_id);
|
|
1351
1153
|
if (params) {
|
|
1352
1154
|
params.forEach((value, key) => {
|
|
1353
1155
|
url.searchParams.set(key, value);
|
|
@@ -1375,15 +1177,14 @@ var TracesManager = class {
|
|
|
1375
1177
|
pagination: data.meta
|
|
1376
1178
|
};
|
|
1377
1179
|
}
|
|
1378
|
-
/**
|
|
1379
|
-
* Get trace detail or specific span
|
|
1380
|
-
* GET /traces/{trace_id}
|
|
1381
|
-
*/
|
|
1382
1180
|
async getTraceDetail(endpoint, traceId, options, headers, params) {
|
|
1383
1181
|
const url = new URL(`${endpoint}/traces/${encodeURIComponent(traceId)}`);
|
|
1384
|
-
if (options.span_id)
|
|
1385
|
-
|
|
1386
|
-
if (options.
|
|
1182
|
+
if (options.span_id)
|
|
1183
|
+
url.searchParams.set("span_id", options.span_id);
|
|
1184
|
+
if (options.run_id)
|
|
1185
|
+
url.searchParams.set("run_id", options.run_id);
|
|
1186
|
+
if (options.db_id)
|
|
1187
|
+
url.searchParams.set("db_id", options.db_id);
|
|
1387
1188
|
if (params) {
|
|
1388
1189
|
params.forEach((value, key) => {
|
|
1389
1190
|
url.searchParams.set(key, value);
|
|
@@ -1395,21 +1196,26 @@ var TracesManager = class {
|
|
|
1395
1196
|
}
|
|
1396
1197
|
return await response.json();
|
|
1397
1198
|
}
|
|
1398
|
-
/**
|
|
1399
|
-
* Get trace session statistics
|
|
1400
|
-
* GET /trace_session_stats
|
|
1401
|
-
*/
|
|
1402
1199
|
async getTraceSessionStats(endpoint, options, headers, params) {
|
|
1403
1200
|
const url = new URL(`${endpoint}/trace_session_stats`);
|
|
1404
|
-
if (options.user_id)
|
|
1405
|
-
|
|
1406
|
-
if (options.
|
|
1407
|
-
|
|
1408
|
-
if (options.
|
|
1409
|
-
|
|
1410
|
-
if (options.
|
|
1411
|
-
|
|
1412
|
-
if (options.
|
|
1201
|
+
if (options.user_id)
|
|
1202
|
+
url.searchParams.set("user_id", options.user_id);
|
|
1203
|
+
if (options.agent_id)
|
|
1204
|
+
url.searchParams.set("agent_id", options.agent_id);
|
|
1205
|
+
if (options.team_id)
|
|
1206
|
+
url.searchParams.set("team_id", options.team_id);
|
|
1207
|
+
if (options.workflow_id)
|
|
1208
|
+
url.searchParams.set("workflow_id", options.workflow_id);
|
|
1209
|
+
if (options.start_time)
|
|
1210
|
+
url.searchParams.set("start_time", options.start_time);
|
|
1211
|
+
if (options.end_time)
|
|
1212
|
+
url.searchParams.set("end_time", options.end_time);
|
|
1213
|
+
if (options.page !== undefined)
|
|
1214
|
+
url.searchParams.set("page", String(options.page));
|
|
1215
|
+
if (options.limit !== undefined)
|
|
1216
|
+
url.searchParams.set("limit", String(options.limit));
|
|
1217
|
+
if (options.db_id)
|
|
1218
|
+
url.searchParams.set("db_id", options.db_id);
|
|
1413
1219
|
if (params) {
|
|
1414
1220
|
params.forEach((value, key) => {
|
|
1415
1221
|
url.searchParams.set(key, value);
|
|
@@ -1437,7 +1243,7 @@ var TracesManager = class {
|
|
|
1437
1243
|
pagination: data.meta
|
|
1438
1244
|
};
|
|
1439
1245
|
}
|
|
1440
|
-
}
|
|
1246
|
+
}
|
|
1441
1247
|
|
|
1442
1248
|
// src/processors/event-processor.ts
|
|
1443
1249
|
var import_agno_types = require("@rodrigocoliveira/agno-types");
|
|
@@ -1457,9 +1263,7 @@ ${jsonString}
|
|
|
1457
1263
|
// src/processors/event-processor.ts
|
|
1458
1264
|
function processToolCall(toolCall, prevToolCalls = []) {
|
|
1459
1265
|
const toolCallId = toolCall.tool_call_id || `${toolCall.tool_name}-${toolCall.created_at}`;
|
|
1460
|
-
const existingToolCallIndex = prevToolCalls.findIndex(
|
|
1461
|
-
(tc) => tc.tool_call_id && tc.tool_call_id === toolCall.tool_call_id || !tc.tool_call_id && toolCall.tool_name && toolCall.created_at && `${tc.tool_name}-${tc.created_at}` === toolCallId
|
|
1462
|
-
);
|
|
1266
|
+
const existingToolCallIndex = prevToolCalls.findIndex((tc) => tc.tool_call_id && tc.tool_call_id === toolCall.tool_call_id || !tc.tool_call_id && toolCall.tool_name && toolCall.created_at && `${tc.tool_name}-${tc.created_at}` === toolCallId);
|
|
1463
1267
|
if (existingToolCallIndex >= 0) {
|
|
1464
1268
|
const updatedToolCalls = [...prevToolCalls];
|
|
1465
1269
|
updatedToolCalls[existingToolCallIndex] = {
|
|
@@ -1483,13 +1287,9 @@ function processChunkToolCalls(chunk, existingToolCalls = []) {
|
|
|
1483
1287
|
}
|
|
1484
1288
|
return updatedToolCalls;
|
|
1485
1289
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
}
|
|
1490
|
-
/**
|
|
1491
|
-
* Process a chunk and update the last message
|
|
1492
|
-
*/
|
|
1290
|
+
|
|
1291
|
+
class EventProcessor {
|
|
1292
|
+
lastContent = "";
|
|
1493
1293
|
processChunk(chunk, lastMessage) {
|
|
1494
1294
|
if (!lastMessage || lastMessage.role !== "agent") {
|
|
1495
1295
|
return lastMessage;
|
|
@@ -1506,10 +1306,7 @@ var EventProcessor = class {
|
|
|
1506
1306
|
case import_agno_types.RunEvent.TeamToolCallStarted:
|
|
1507
1307
|
case import_agno_types.RunEvent.ToolCallCompleted:
|
|
1508
1308
|
case import_agno_types.RunEvent.TeamToolCallCompleted:
|
|
1509
|
-
updatedMessage.tool_calls = processChunkToolCalls(
|
|
1510
|
-
chunk,
|
|
1511
|
-
lastMessage.tool_calls
|
|
1512
|
-
);
|
|
1309
|
+
updatedMessage.tool_calls = processChunkToolCalls(chunk, lastMessage.tool_calls);
|
|
1513
1310
|
break;
|
|
1514
1311
|
case import_agno_types.RunEvent.RunContent:
|
|
1515
1312
|
case import_agno_types.RunEvent.TeamRunContent:
|
|
@@ -1522,10 +1319,7 @@ var EventProcessor = class {
|
|
|
1522
1319
|
updatedMessage.content = updatedMessage.content + jsonBlock;
|
|
1523
1320
|
this.lastContent = jsonBlock;
|
|
1524
1321
|
}
|
|
1525
|
-
updatedMessage.tool_calls = processChunkToolCalls(
|
|
1526
|
-
chunk,
|
|
1527
|
-
lastMessage.tool_calls
|
|
1528
|
-
);
|
|
1322
|
+
updatedMessage.tool_calls = processChunkToolCalls(chunk, lastMessage.tool_calls);
|
|
1529
1323
|
if (chunk.extra_data?.reasoning_steps) {
|
|
1530
1324
|
updatedMessage.extra_data = {
|
|
1531
1325
|
...updatedMessage.extra_data,
|
|
@@ -1587,10 +1381,7 @@ var EventProcessor = class {
|
|
|
1587
1381
|
}
|
|
1588
1382
|
}
|
|
1589
1383
|
updatedMessage.content = updatedContent;
|
|
1590
|
-
updatedMessage.tool_calls = processChunkToolCalls(
|
|
1591
|
-
chunk,
|
|
1592
|
-
lastMessage.tool_calls
|
|
1593
|
-
);
|
|
1384
|
+
updatedMessage.tool_calls = processChunkToolCalls(chunk, lastMessage.tool_calls);
|
|
1594
1385
|
updatedMessage.images = chunk.images ?? lastMessage.images;
|
|
1595
1386
|
updatedMessage.videos = chunk.videos ?? lastMessage.videos;
|
|
1596
1387
|
updatedMessage.response_audio = chunk.response_audio;
|
|
@@ -1605,8 +1396,6 @@ var EventProcessor = class {
|
|
|
1605
1396
|
case import_agno_types.RunEvent.TeamMemoryUpdateCompleted:
|
|
1606
1397
|
break;
|
|
1607
1398
|
case import_agno_types.RunEvent.RunPaused:
|
|
1608
|
-
// Run paused for HITL - handled at client level
|
|
1609
|
-
// Don't update the message, just let the client emit run:paused event
|
|
1610
1399
|
case import_agno_types.RunEvent.CustomEvent:
|
|
1611
1400
|
break;
|
|
1612
1401
|
case import_agno_types.RunEvent.RunCancelled:
|
|
@@ -1620,13 +1409,10 @@ var EventProcessor = class {
|
|
|
1620
1409
|
}
|
|
1621
1410
|
return updatedMessage;
|
|
1622
1411
|
}
|
|
1623
|
-
/**
|
|
1624
|
-
* Reset the processor state (e.g., between messages)
|
|
1625
|
-
*/
|
|
1626
1412
|
reset() {
|
|
1627
1413
|
this.lastContent = "";
|
|
1628
1414
|
}
|
|
1629
|
-
}
|
|
1415
|
+
}
|
|
1630
1416
|
|
|
1631
1417
|
// src/parsers/stream-parser.ts
|
|
1632
1418
|
function isLegacyFormat(data) {
|
|
@@ -1661,7 +1447,7 @@ function parseBuffer(buffer, onChunk) {
|
|
|
1661
1447
|
let escapeNext = false;
|
|
1662
1448
|
let jsonEndIndex = -1;
|
|
1663
1449
|
let i = jsonStartIndex;
|
|
1664
|
-
for (;
|
|
1450
|
+
for (;i < buffer.length; i++) {
|
|
1665
1451
|
const char = buffer[i];
|
|
1666
1452
|
if (inString) {
|
|
1667
1453
|
if (escapeNext) {
|
|
@@ -1751,8 +1537,7 @@ async function streamResponse(options) {
|
|
|
1751
1537
|
try {
|
|
1752
1538
|
const errorData = await response.json();
|
|
1753
1539
|
errorMessage = errorData.detail || errorData.message || errorMessage;
|
|
1754
|
-
} catch {
|
|
1755
|
-
}
|
|
1540
|
+
} catch {}
|
|
1756
1541
|
}
|
|
1757
1542
|
const error = new Error(errorMessage);
|
|
1758
1543
|
error.status = response.status;
|
|
@@ -1762,7 +1547,7 @@ async function streamResponse(options) {
|
|
|
1762
1547
|
throw new Error("No response body");
|
|
1763
1548
|
}
|
|
1764
1549
|
const reader = response.body.getReader();
|
|
1765
|
-
const decoder = new TextDecoder
|
|
1550
|
+
const decoder = new TextDecoder;
|
|
1766
1551
|
const processStream = async () => {
|
|
1767
1552
|
while (true) {
|
|
1768
1553
|
const { done, value } = await reader.read();
|
|
@@ -1791,7 +1576,7 @@ async function streamResponse(options) {
|
|
|
1791
1576
|
// src/utils/logger.ts
|
|
1792
1577
|
var SENSITIVE_KEYS = ["authToken", "Authorization", "token", "password", "apiKey"];
|
|
1793
1578
|
function sanitizeObject(obj) {
|
|
1794
|
-
if (obj === null || obj ===
|
|
1579
|
+
if (obj === null || obj === undefined) {
|
|
1795
1580
|
return obj;
|
|
1796
1581
|
}
|
|
1797
1582
|
if (typeof obj !== "object") {
|
|
@@ -1802,10 +1587,8 @@ function sanitizeObject(obj) {
|
|
|
1802
1587
|
}
|
|
1803
1588
|
const sanitized = {};
|
|
1804
1589
|
for (const [key, value] of Object.entries(obj)) {
|
|
1805
|
-
if (SENSITIVE_KEYS.some(
|
|
1806
|
-
|
|
1807
|
-
)) {
|
|
1808
|
-
sanitized[key] = value ? "[REDACTED]" : void 0;
|
|
1590
|
+
if (SENSITIVE_KEYS.some((sensitiveKey) => key.toLowerCase().includes(sensitiveKey.toLowerCase()))) {
|
|
1591
|
+
sanitized[key] = value ? "[REDACTED]" : undefined;
|
|
1809
1592
|
} else if (typeof value === "object" && value !== null) {
|
|
1810
1593
|
sanitized[key] = sanitizeObject(value);
|
|
1811
1594
|
} else {
|
|
@@ -1817,67 +1600,68 @@ function sanitizeObject(obj) {
|
|
|
1817
1600
|
function isDevelopment() {
|
|
1818
1601
|
return typeof process !== "undefined" && process.env?.NODE_ENV === "development";
|
|
1819
1602
|
}
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
* Log debug information (only in development)
|
|
1823
|
-
*/
|
|
1603
|
+
|
|
1604
|
+
class Logger {
|
|
1824
1605
|
static debug(message, data) {
|
|
1825
1606
|
if (isDevelopment()) {
|
|
1826
|
-
const sanitized = data ? sanitizeObject(data) :
|
|
1607
|
+
const sanitized = data ? sanitizeObject(data) : undefined;
|
|
1827
1608
|
console.debug(`[DEBUG] ${message}`, sanitized || "");
|
|
1828
1609
|
}
|
|
1829
1610
|
}
|
|
1830
|
-
/**
|
|
1831
|
-
* Log informational messages (only in development)
|
|
1832
|
-
*/
|
|
1833
1611
|
static info(message, data) {
|
|
1834
1612
|
if (isDevelopment()) {
|
|
1835
|
-
const sanitized = data ? sanitizeObject(data) :
|
|
1613
|
+
const sanitized = data ? sanitizeObject(data) : undefined;
|
|
1836
1614
|
console.info(`[INFO] ${message}`, sanitized || "");
|
|
1837
1615
|
}
|
|
1838
1616
|
}
|
|
1839
|
-
/**
|
|
1840
|
-
* Log warnings (always logs)
|
|
1841
|
-
*/
|
|
1842
1617
|
static warn(message, data) {
|
|
1843
|
-
const sanitized = data ? sanitizeObject(data) :
|
|
1618
|
+
const sanitized = data ? sanitizeObject(data) : undefined;
|
|
1844
1619
|
console.warn(`[WARN] ${message}`, sanitized || "");
|
|
1845
1620
|
}
|
|
1846
|
-
/**
|
|
1847
|
-
* Log errors (always logs)
|
|
1848
|
-
*/
|
|
1849
1621
|
static error(message, data) {
|
|
1850
|
-
const sanitized = data ? sanitizeObject(data) :
|
|
1622
|
+
const sanitized = data ? sanitizeObject(data) : undefined;
|
|
1851
1623
|
console.error(`[ERROR] ${message}`, sanitized || "");
|
|
1852
1624
|
}
|
|
1853
|
-
}
|
|
1625
|
+
}
|
|
1854
1626
|
|
|
1855
1627
|
// src/client.ts
|
|
1856
1628
|
function toSafeISOString(timestamp) {
|
|
1857
1629
|
const now = Date.now();
|
|
1858
|
-
const ts = timestamp ? timestamp *
|
|
1859
|
-
const MIN_TIMESTAMP =
|
|
1860
|
-
const MAX_TIMESTAMP =
|
|
1630
|
+
const ts = timestamp ? timestamp * 1000 : now;
|
|
1631
|
+
const MIN_TIMESTAMP = 946684800000;
|
|
1632
|
+
const MAX_TIMESTAMP = 4102444800000;
|
|
1861
1633
|
if (ts < MIN_TIMESTAMP || ts > MAX_TIMESTAMP || !Number.isFinite(ts)) {
|
|
1862
1634
|
Logger.warn(`Invalid timestamp: ${timestamp}, using current time`);
|
|
1863
1635
|
return new Date(now).toISOString();
|
|
1864
1636
|
}
|
|
1865
1637
|
return new Date(ts).toISOString();
|
|
1866
1638
|
}
|
|
1867
|
-
|
|
1639
|
+
|
|
1640
|
+
class AgnoClient extends import_eventemitter3.default {
|
|
1641
|
+
messageStore;
|
|
1642
|
+
configManager;
|
|
1643
|
+
sessionManager;
|
|
1644
|
+
memoryManager;
|
|
1645
|
+
knowledgeManager;
|
|
1646
|
+
evalManager;
|
|
1647
|
+
tracesManager;
|
|
1648
|
+
eventProcessor;
|
|
1649
|
+
state;
|
|
1650
|
+
pendingUISpecs;
|
|
1651
|
+
runCompletedSuccessfully = false;
|
|
1652
|
+
currentRunId;
|
|
1653
|
+
abortController;
|
|
1868
1654
|
constructor(config) {
|
|
1869
1655
|
super();
|
|
1870
|
-
|
|
1871
|
-
this.runCompletedSuccessfully = false;
|
|
1872
|
-
this.messageStore = new MessageStore();
|
|
1656
|
+
this.messageStore = new MessageStore;
|
|
1873
1657
|
this.configManager = new ConfigManager(config);
|
|
1874
|
-
this.sessionManager = new SessionManager
|
|
1875
|
-
this.memoryManager = new MemoryManager
|
|
1876
|
-
this.knowledgeManager = new KnowledgeManager
|
|
1877
|
-
this.evalManager = new EvalManager
|
|
1878
|
-
this.tracesManager = new TracesManager
|
|
1879
|
-
this.eventProcessor = new EventProcessor
|
|
1880
|
-
this.pendingUISpecs =
|
|
1658
|
+
this.sessionManager = new SessionManager;
|
|
1659
|
+
this.memoryManager = new MemoryManager;
|
|
1660
|
+
this.knowledgeManager = new KnowledgeManager;
|
|
1661
|
+
this.evalManager = new EvalManager;
|
|
1662
|
+
this.tracesManager = new TracesManager;
|
|
1663
|
+
this.eventProcessor = new EventProcessor;
|
|
1664
|
+
this.pendingUISpecs = new Map;
|
|
1881
1665
|
this.state = {
|
|
1882
1666
|
isStreaming: false,
|
|
1883
1667
|
isRefreshing: false,
|
|
@@ -1886,9 +1670,9 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
1886
1670
|
teams: [],
|
|
1887
1671
|
sessions: [],
|
|
1888
1672
|
isPaused: false,
|
|
1889
|
-
pausedRunId:
|
|
1890
|
-
toolsAwaitingExecution:
|
|
1891
|
-
currentRunId:
|
|
1673
|
+
pausedRunId: undefined,
|
|
1674
|
+
toolsAwaitingExecution: undefined,
|
|
1675
|
+
currentRunId: undefined,
|
|
1892
1676
|
isCancelling: false,
|
|
1893
1677
|
memories: [],
|
|
1894
1678
|
memoryTopics: [],
|
|
@@ -1896,63 +1680,41 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
1896
1680
|
traceSessionStats: []
|
|
1897
1681
|
};
|
|
1898
1682
|
}
|
|
1899
|
-
/**
|
|
1900
|
-
* Get current messages
|
|
1901
|
-
*/
|
|
1902
1683
|
getMessages() {
|
|
1903
1684
|
return this.messageStore.getMessages();
|
|
1904
1685
|
}
|
|
1905
|
-
/**
|
|
1906
|
-
* Get current configuration
|
|
1907
|
-
*/
|
|
1908
1686
|
getConfig() {
|
|
1909
1687
|
return this.configManager.getConfig();
|
|
1910
1688
|
}
|
|
1911
|
-
/**
|
|
1912
|
-
* Get current state
|
|
1913
|
-
*/
|
|
1914
1689
|
getState() {
|
|
1915
1690
|
return { ...this.state };
|
|
1916
1691
|
}
|
|
1917
|
-
/**
|
|
1918
|
-
* Update configuration
|
|
1919
|
-
*/
|
|
1920
1692
|
updateConfig(updates) {
|
|
1921
1693
|
this.configManager.updateConfig(updates);
|
|
1922
1694
|
this.emit("config:change", this.configManager.getConfig());
|
|
1923
1695
|
}
|
|
1924
|
-
/**
|
|
1925
|
-
* Clear all messages
|
|
1926
|
-
*/
|
|
1927
1696
|
clearMessages() {
|
|
1928
1697
|
this.messageStore.clear();
|
|
1929
|
-
this.configManager.setSessionId(
|
|
1698
|
+
this.configManager.setSessionId(undefined);
|
|
1930
1699
|
this.pendingUISpecs.clear();
|
|
1931
1700
|
this.emit("message:update", this.messageStore.getMessages());
|
|
1932
1701
|
this.emit("state:change", this.getState());
|
|
1933
1702
|
}
|
|
1934
|
-
/**
|
|
1935
|
-
* Send a message to the agent/team (streaming)
|
|
1936
|
-
*
|
|
1937
|
-
* To cancel a running request, use the `cancelRun()` method which:
|
|
1938
|
-
* 1. Aborts the local fetch stream (immediate UI feedback)
|
|
1939
|
-
* 2. Notifies the backend to stop processing (saves compute costs)
|
|
1940
|
-
*/
|
|
1941
1703
|
async sendMessage(message, options) {
|
|
1942
1704
|
if (this.state.isStreaming) {
|
|
1943
1705
|
throw new Error("Already streaming a message");
|
|
1944
1706
|
}
|
|
1945
1707
|
this.runCompletedSuccessfully = false;
|
|
1946
|
-
this.abortController = new AbortController
|
|
1708
|
+
this.abortController = new AbortController;
|
|
1947
1709
|
const runUrl = this.configManager.getRunUrl();
|
|
1948
1710
|
if (!runUrl) {
|
|
1949
1711
|
throw new Error("No agent or team selected");
|
|
1950
1712
|
}
|
|
1951
1713
|
this.state.isStreaming = true;
|
|
1952
|
-
this.state.errorMessage =
|
|
1714
|
+
this.state.errorMessage = undefined;
|
|
1953
1715
|
this.emit("stream:start");
|
|
1954
1716
|
this.emit("state:change", this.getState());
|
|
1955
|
-
const formData = message instanceof FormData ? message : new FormData
|
|
1717
|
+
const formData = message instanceof FormData ? message : new FormData;
|
|
1956
1718
|
if (typeof message === "string") {
|
|
1957
1719
|
formData.append("message", message);
|
|
1958
1720
|
}
|
|
@@ -1991,7 +1753,7 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
1991
1753
|
this.messageStore.addMessage({
|
|
1992
1754
|
role: "user",
|
|
1993
1755
|
content: formData.get("message"),
|
|
1994
|
-
created_at: Math.floor(Date.now() /
|
|
1756
|
+
created_at: Math.floor(Date.now() / 1000),
|
|
1995
1757
|
...userImages.length > 0 ? { images: userImages } : {},
|
|
1996
1758
|
...userAudio.length > 0 ? { audio: userAudio } : {},
|
|
1997
1759
|
...userFiles.length > 0 ? { files: userFiles } : {}
|
|
@@ -2001,7 +1763,7 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2001
1763
|
content: "",
|
|
2002
1764
|
tool_calls: [],
|
|
2003
1765
|
streamingError: false,
|
|
2004
|
-
created_at: Math.floor(Date.now() /
|
|
1766
|
+
created_at: Math.floor(Date.now() / 1000) + 1
|
|
2005
1767
|
});
|
|
2006
1768
|
this.emit("message:update", this.messageStore.getMessages());
|
|
2007
1769
|
this.eventProcessor.reset();
|
|
@@ -2036,9 +1798,9 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2036
1798
|
},
|
|
2037
1799
|
onComplete: async () => {
|
|
2038
1800
|
this.state.isStreaming = false;
|
|
2039
|
-
this.currentRunId =
|
|
2040
|
-
this.state.currentRunId =
|
|
2041
|
-
this.abortController =
|
|
1801
|
+
this.currentRunId = undefined;
|
|
1802
|
+
this.state.currentRunId = undefined;
|
|
1803
|
+
this.abortController = undefined;
|
|
2042
1804
|
this.emit("stream:end");
|
|
2043
1805
|
this.emit("message:complete", this.messageStore.getMessages());
|
|
2044
1806
|
this.emit("state:change", this.getState());
|
|
@@ -2049,21 +1811,9 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2049
1811
|
}
|
|
2050
1812
|
});
|
|
2051
1813
|
}
|
|
2052
|
-
/**
|
|
2053
|
-
* Determine if a RunEvent is a team-level event (prefixed with "Team")
|
|
2054
|
-
*/
|
|
2055
1814
|
isTeamEvent(event) {
|
|
2056
1815
|
return event.toString().startsWith("Team");
|
|
2057
1816
|
}
|
|
2058
|
-
/**
|
|
2059
|
-
* Determine if an event should update the user-facing message based on mode.
|
|
2060
|
-
*
|
|
2061
|
-
* In team mode: only Team* events should update the user-facing message.
|
|
2062
|
-
* In agent mode: only Run* (non-Team) events should update the user-facing message.
|
|
2063
|
-
*
|
|
2064
|
-
* Certain events are always processed regardless of mode:
|
|
2065
|
-
* - CustomEvent, RunPaused, RunContinued (control flow events)
|
|
2066
|
-
*/
|
|
2067
1817
|
shouldProcessForUserMessage(event) {
|
|
2068
1818
|
if (event === import_agno_types2.RunEvent.CustomEvent || event === import_agno_types2.RunEvent.RunPaused || event === import_agno_types2.RunEvent.RunContinued) {
|
|
2069
1819
|
return true;
|
|
@@ -2075,12 +1825,9 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2075
1825
|
}
|
|
2076
1826
|
return !isTeam;
|
|
2077
1827
|
}
|
|
2078
|
-
/**
|
|
2079
|
-
* Emit member-specific events for internal team member activity.
|
|
2080
|
-
* Only emits when emitMemberEvents config option is true.
|
|
2081
|
-
*/
|
|
2082
1828
|
emitMemberEvent(event, chunk) {
|
|
2083
|
-
if (!this.configManager.getEmitMemberEvents())
|
|
1829
|
+
if (!this.configManager.getEmitMemberEvents())
|
|
1830
|
+
return;
|
|
2084
1831
|
this.emit("member:event", chunk);
|
|
2085
1832
|
if (event === import_agno_types2.RunEvent.RunStarted) {
|
|
2086
1833
|
this.emit("member:started", chunk);
|
|
@@ -2092,9 +1839,6 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2092
1839
|
this.emit("member:error", chunk);
|
|
2093
1840
|
}
|
|
2094
1841
|
}
|
|
2095
|
-
/**
|
|
2096
|
-
* Handle streaming chunk
|
|
2097
|
-
*/
|
|
2098
1842
|
handleChunk(chunk, currentSessionId, messageContent) {
|
|
2099
1843
|
const event = chunk.event;
|
|
2100
1844
|
if (event === import_agno_types2.RunEvent.RunStarted || event === import_agno_types2.RunEvent.TeamRunStarted || event === import_agno_types2.RunEvent.ReasoningStarted || event === import_agno_types2.RunEvent.TeamReasoningStarted) {
|
|
@@ -2109,9 +1853,7 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2109
1853
|
session_name: messageContent,
|
|
2110
1854
|
created_at: toSafeISOString(chunk.created_at)
|
|
2111
1855
|
};
|
|
2112
|
-
const sessionExists = this.state.sessions.some(
|
|
2113
|
-
(s) => s.session_id === chunk.session_id
|
|
2114
|
-
);
|
|
1856
|
+
const sessionExists = this.state.sessions.some((s) => s.session_id === chunk.session_id);
|
|
2115
1857
|
if (!sessionExists) {
|
|
2116
1858
|
this.state.sessions = [sessionData, ...this.state.sessions];
|
|
2117
1859
|
this.emit("session:created", sessionData);
|
|
@@ -2147,9 +1889,7 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2147
1889
|
streamingError: true
|
|
2148
1890
|
}));
|
|
2149
1891
|
if (chunk.session_id) {
|
|
2150
|
-
this.state.sessions = this.state.sessions.filter(
|
|
2151
|
-
(s) => s.session_id !== chunk.session_id
|
|
2152
|
-
);
|
|
1892
|
+
this.state.sessions = this.state.sessions.filter((s) => s.session_id !== chunk.session_id);
|
|
2153
1893
|
}
|
|
2154
1894
|
this.emit("message:error", errorContent);
|
|
2155
1895
|
return;
|
|
@@ -2167,9 +1907,6 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2167
1907
|
}
|
|
2168
1908
|
this.emit("message:update", this.messageStore.getMessages());
|
|
2169
1909
|
}
|
|
2170
|
-
/**
|
|
2171
|
-
* Handle error
|
|
2172
|
-
*/
|
|
2173
1910
|
handleError(error, sessionId) {
|
|
2174
1911
|
this.state.isStreaming = false;
|
|
2175
1912
|
this.state.errorMessage = error.message;
|
|
@@ -2178,24 +1915,18 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2178
1915
|
streamingError: true
|
|
2179
1916
|
}));
|
|
2180
1917
|
if (sessionId) {
|
|
2181
|
-
this.state.sessions = this.state.sessions.filter(
|
|
2182
|
-
(s) => s.session_id !== sessionId
|
|
2183
|
-
);
|
|
1918
|
+
this.state.sessions = this.state.sessions.filter((s) => s.session_id !== sessionId);
|
|
2184
1919
|
}
|
|
2185
1920
|
this.emit("message:error", error.message);
|
|
2186
1921
|
this.emit("stream:end");
|
|
2187
1922
|
this.emit("state:change", this.getState());
|
|
2188
1923
|
}
|
|
2189
|
-
/**
|
|
2190
|
-
* Handle RunCancelled event from backend
|
|
2191
|
-
* Cancellation is user-initiated and distinct from errors
|
|
2192
|
-
*/
|
|
2193
1924
|
handleRunCancelled(chunk) {
|
|
2194
1925
|
this.state.isStreaming = false;
|
|
2195
1926
|
this.state.isCancelling = false;
|
|
2196
|
-
this.state.currentRunId =
|
|
2197
|
-
this.currentRunId =
|
|
2198
|
-
this.abortController =
|
|
1927
|
+
this.state.currentRunId = undefined;
|
|
1928
|
+
this.currentRunId = undefined;
|
|
1929
|
+
this.abortController = undefined;
|
|
2199
1930
|
this.messageStore.updateLastMessage((msg) => ({
|
|
2200
1931
|
...msg,
|
|
2201
1932
|
cancelled: true
|
|
@@ -2208,18 +1939,14 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2208
1939
|
this.emit("message:update", this.messageStore.getMessages());
|
|
2209
1940
|
this.emit("state:change", this.getState());
|
|
2210
1941
|
}
|
|
2211
|
-
/**
|
|
2212
|
-
* Handle local cancellation cleanup
|
|
2213
|
-
* Called when user cancels, regardless of backend response
|
|
2214
|
-
*/
|
|
2215
1942
|
handleLocalCancellation() {
|
|
2216
1943
|
const runId = this.currentRunId;
|
|
2217
1944
|
const sessionId = this.configManager.getSessionId();
|
|
2218
1945
|
this.state.isStreaming = false;
|
|
2219
1946
|
this.state.isCancelling = false;
|
|
2220
|
-
this.state.currentRunId =
|
|
2221
|
-
this.currentRunId =
|
|
2222
|
-
this.abortController =
|
|
1947
|
+
this.state.currentRunId = undefined;
|
|
1948
|
+
this.currentRunId = undefined;
|
|
1949
|
+
this.abortController = undefined;
|
|
2223
1950
|
this.messageStore.updateLastMessage((msg) => ({
|
|
2224
1951
|
...msg,
|
|
2225
1952
|
cancelled: true
|
|
@@ -2229,23 +1956,14 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2229
1956
|
this.emit("message:update", this.messageStore.getMessages());
|
|
2230
1957
|
this.emit("state:change", this.getState());
|
|
2231
1958
|
}
|
|
2232
|
-
/**
|
|
2233
|
-
* Check if an error is a 401 Unauthorized error with "Token has expired" detail.
|
|
2234
|
-
* Only triggers token refresh for expired tokens, not other auth failures.
|
|
2235
|
-
*/
|
|
2236
1959
|
isTokenExpiredError(error) {
|
|
2237
|
-
if (!(error instanceof Error))
|
|
1960
|
+
if (!(error instanceof Error))
|
|
1961
|
+
return false;
|
|
2238
1962
|
const errorWithStatus = error;
|
|
2239
1963
|
const is401 = errorWithStatus.status === 401 || error.message.includes("401");
|
|
2240
1964
|
const isExpired = error.message.toLowerCase().includes("token has expired");
|
|
2241
1965
|
return is401 && isExpired;
|
|
2242
1966
|
}
|
|
2243
|
-
/**
|
|
2244
|
-
* Attempt to refresh the token using the onTokenExpired callback.
|
|
2245
|
-
* If successful, updates the auth token in config.
|
|
2246
|
-
*
|
|
2247
|
-
* @returns true if token was refreshed, false otherwise
|
|
2248
|
-
*/
|
|
2249
1967
|
async tryRefreshToken() {
|
|
2250
1968
|
const onTokenExpired = this.configManager.getOnTokenExpired();
|
|
2251
1969
|
if (!onTokenExpired) {
|
|
@@ -2263,14 +1981,6 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2263
1981
|
}
|
|
2264
1982
|
return false;
|
|
2265
1983
|
}
|
|
2266
|
-
/**
|
|
2267
|
-
* Execute an operation with automatic token refresh on 401 Unauthorized.
|
|
2268
|
-
* Centralizes the token refresh and retry logic for all non-streaming API calls.
|
|
2269
|
-
*
|
|
2270
|
-
* @param operation - A function that performs the API call and returns a Promise
|
|
2271
|
-
* @returns The result of the operation
|
|
2272
|
-
* @throws The original error if it's not a 401 or if token refresh fails
|
|
2273
|
-
*/
|
|
2274
1984
|
async withTokenRefresh(operation) {
|
|
2275
1985
|
try {
|
|
2276
1986
|
return await operation();
|
|
@@ -2284,12 +1994,6 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2284
1994
|
throw error;
|
|
2285
1995
|
}
|
|
2286
1996
|
}
|
|
2287
|
-
/**
|
|
2288
|
-
* Execute a streaming request with automatic token refresh on 401 Unauthorized.
|
|
2289
|
-
* This method handles the complexity of rebuilding headers after token refresh.
|
|
2290
|
-
*
|
|
2291
|
-
* @param config - Configuration for the streaming request
|
|
2292
|
-
*/
|
|
2293
1997
|
async executeStream(config) {
|
|
2294
1998
|
const executeStream = async () => {
|
|
2295
1999
|
const headers = this.configManager.buildRequestHeaders(config.perRequestHeaders);
|
|
@@ -2315,22 +2019,14 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2315
2019
|
await executeStream();
|
|
2316
2020
|
return;
|
|
2317
2021
|
} catch (retryError) {
|
|
2318
|
-
config.onError(
|
|
2319
|
-
retryError instanceof Error ? retryError : new Error(String(retryError))
|
|
2320
|
-
);
|
|
2022
|
+
config.onError(retryError instanceof Error ? retryError : new Error(String(retryError)));
|
|
2321
2023
|
return;
|
|
2322
2024
|
}
|
|
2323
2025
|
}
|
|
2324
2026
|
}
|
|
2325
|
-
config.onError(
|
|
2326
|
-
error instanceof Error ? error : new Error(String(error))
|
|
2327
|
-
);
|
|
2027
|
+
config.onError(error instanceof Error ? error : new Error(String(error)));
|
|
2328
2028
|
}
|
|
2329
2029
|
}
|
|
2330
|
-
/**
|
|
2331
|
-
* Check if a fetch Response is a 401 with "Token has expired" detail.
|
|
2332
|
-
* Reads the response body to check for the specific error message.
|
|
2333
|
-
*/
|
|
2334
2030
|
async isTokenExpiredResponse(response) {
|
|
2335
2031
|
if (response.status !== 401) {
|
|
2336
2032
|
return false;
|
|
@@ -2344,41 +2040,18 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2344
2040
|
return false;
|
|
2345
2041
|
}
|
|
2346
2042
|
}
|
|
2347
|
-
/**
|
|
2348
|
-
* Wrapper for fetch that handles 401 "Token has expired" errors with automatic token refresh and retry.
|
|
2349
|
-
* Used for non-streaming API calls.
|
|
2350
|
-
*
|
|
2351
|
-
* @param url - The URL to fetch
|
|
2352
|
-
* @param init - Optional fetch init options (method, body, etc.)
|
|
2353
|
-
* @returns The fetch Response
|
|
2354
|
-
*/
|
|
2355
2043
|
async fetchWithTokenRefresh(url, init) {
|
|
2356
|
-
const headers = this.configManager.buildRequestHeaders(
|
|
2357
|
-
init?.headers
|
|
2358
|
-
);
|
|
2044
|
+
const headers = this.configManager.buildRequestHeaders(init?.headers);
|
|
2359
2045
|
let response = await fetch(url, { ...init, headers });
|
|
2360
2046
|
if (await this.isTokenExpiredResponse(response)) {
|
|
2361
2047
|
const refreshed = await this.tryRefreshToken();
|
|
2362
2048
|
if (refreshed) {
|
|
2363
|
-
const newHeaders = this.configManager.buildRequestHeaders(
|
|
2364
|
-
init?.headers
|
|
2365
|
-
);
|
|
2049
|
+
const newHeaders = this.configManager.buildRequestHeaders(init?.headers);
|
|
2366
2050
|
response = await fetch(url, { ...init, headers: newHeaders });
|
|
2367
2051
|
}
|
|
2368
2052
|
}
|
|
2369
2053
|
return response;
|
|
2370
2054
|
}
|
|
2371
|
-
/**
|
|
2372
|
-
* Cancel the current running agent/team run.
|
|
2373
|
-
*
|
|
2374
|
-
* This will:
|
|
2375
|
-
* 1. Abort the local fetch stream (immediate UI feedback)
|
|
2376
|
-
* 2. Notify the backend to stop processing
|
|
2377
|
-
* 3. Emit 'run:cancelled' event
|
|
2378
|
-
*
|
|
2379
|
-
* @param options - Optional request headers and query parameters
|
|
2380
|
-
* @throws Error if no run is currently streaming
|
|
2381
|
-
*/
|
|
2382
2055
|
async cancelRun(options) {
|
|
2383
2056
|
if (!this.state.isStreaming) {
|
|
2384
2057
|
throw new Error("No active run to cancel");
|
|
@@ -2390,7 +2063,7 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2390
2063
|
this.emit("state:change", this.getState());
|
|
2391
2064
|
if (this.abortController) {
|
|
2392
2065
|
this.abortController.abort();
|
|
2393
|
-
this.abortController =
|
|
2066
|
+
this.abortController = undefined;
|
|
2394
2067
|
}
|
|
2395
2068
|
const cancelUrl = this.configManager.getCancelUrl(this.currentRunId);
|
|
2396
2069
|
if (!cancelUrl) {
|
|
@@ -2415,18 +2088,9 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2415
2088
|
}
|
|
2416
2089
|
this.handleLocalCancellation();
|
|
2417
2090
|
}
|
|
2418
|
-
/**
|
|
2419
|
-
* Get current run ID (if streaming)
|
|
2420
|
-
*/
|
|
2421
2091
|
getCurrentRunId() {
|
|
2422
2092
|
return this.currentRunId;
|
|
2423
2093
|
}
|
|
2424
|
-
/**
|
|
2425
|
-
* Refresh messages from the session API after run completion.
|
|
2426
|
-
* Replaces streamed messages with authoritative session data.
|
|
2427
|
-
* Preserves client-side properties like ui_component that aren't stored on the server.
|
|
2428
|
-
* @private
|
|
2429
|
-
*/
|
|
2430
2094
|
async refreshSessionMessages() {
|
|
2431
2095
|
const sessionId = this.configManager.getSessionId();
|
|
2432
2096
|
if (!sessionId) {
|
|
@@ -2436,7 +2100,7 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2436
2100
|
this.state.isRefreshing = true;
|
|
2437
2101
|
this.emit("state:change", this.getState());
|
|
2438
2102
|
try {
|
|
2439
|
-
const existingUIComponents =
|
|
2103
|
+
const existingUIComponents = new Map;
|
|
2440
2104
|
const existingUserAttachments = [];
|
|
2441
2105
|
for (const message of this.messageStore.getMessages()) {
|
|
2442
2106
|
if (message.tool_calls) {
|
|
@@ -2461,21 +2125,13 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2461
2125
|
const params = this.configManager.buildQueryString();
|
|
2462
2126
|
const response = await this.withTokenRefresh(() => {
|
|
2463
2127
|
const headers = this.configManager.buildRequestHeaders();
|
|
2464
|
-
return this.sessionManager.fetchSession(
|
|
2465
|
-
config.endpoint,
|
|
2466
|
-
entityType,
|
|
2467
|
-
sessionId,
|
|
2468
|
-
dbId,
|
|
2469
|
-
headers,
|
|
2470
|
-
userId,
|
|
2471
|
-
params
|
|
2472
|
-
);
|
|
2128
|
+
return this.sessionManager.fetchSession(config.endpoint, entityType, sessionId, dbId, headers, userId, params);
|
|
2473
2129
|
});
|
|
2474
2130
|
const messages = this.sessionManager.convertSessionToMessages(response);
|
|
2475
2131
|
if (existingUIComponents.size > 0) {
|
|
2476
2132
|
for (const message of messages) {
|
|
2477
2133
|
if (message.tool_calls) {
|
|
2478
|
-
for (let i = 0;
|
|
2134
|
+
for (let i = 0;i < message.tool_calls.length; i++) {
|
|
2479
2135
|
const toolCall = message.tool_calls[i];
|
|
2480
2136
|
const uiComponent = existingUIComponents.get(toolCall.tool_call_id);
|
|
2481
2137
|
if (uiComponent) {
|
|
@@ -2515,9 +2171,6 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2515
2171
|
this.emit("state:change", this.getState());
|
|
2516
2172
|
}
|
|
2517
2173
|
}
|
|
2518
|
-
/**
|
|
2519
|
-
* Load a session
|
|
2520
|
-
*/
|
|
2521
2174
|
async loadSession(sessionId, options) {
|
|
2522
2175
|
Logger.debug("[AgnoClient] loadSession called with sessionId:", sessionId);
|
|
2523
2176
|
const config = this.configManager.getConfig();
|
|
@@ -2528,15 +2181,7 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2528
2181
|
const params = this.configManager.buildQueryString(options?.params);
|
|
2529
2182
|
const response = await this.withTokenRefresh(() => {
|
|
2530
2183
|
const headers = this.configManager.buildRequestHeaders();
|
|
2531
|
-
return this.sessionManager.fetchSession(
|
|
2532
|
-
config.endpoint,
|
|
2533
|
-
entityType,
|
|
2534
|
-
sessionId,
|
|
2535
|
-
dbId,
|
|
2536
|
-
headers,
|
|
2537
|
-
userId,
|
|
2538
|
-
params
|
|
2539
|
-
);
|
|
2184
|
+
return this.sessionManager.fetchSession(config.endpoint, entityType, sessionId, dbId, headers, userId, params);
|
|
2540
2185
|
});
|
|
2541
2186
|
const messages = this.sessionManager.convertSessionToMessages(response);
|
|
2542
2187
|
Logger.debug("[AgnoClient] Setting messages to store:", `${messages.length} messages`);
|
|
@@ -2549,9 +2194,6 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2549
2194
|
Logger.debug("[AgnoClient] Events emitted, returning messages");
|
|
2550
2195
|
return messages;
|
|
2551
2196
|
}
|
|
2552
|
-
/**
|
|
2553
|
-
* Fetch all sessions
|
|
2554
|
-
*/
|
|
2555
2197
|
async fetchSessions(options) {
|
|
2556
2198
|
const config = this.configManager.getConfig();
|
|
2557
2199
|
const entityType = this.configManager.getMode();
|
|
@@ -2563,48 +2205,27 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2563
2205
|
const params = this.configManager.buildQueryString(options?.params);
|
|
2564
2206
|
const sessions = await this.withTokenRefresh(() => {
|
|
2565
2207
|
const headers = this.configManager.buildRequestHeaders();
|
|
2566
|
-
return this.sessionManager.fetchSessions(
|
|
2567
|
-
config.endpoint,
|
|
2568
|
-
entityType,
|
|
2569
|
-
entityId,
|
|
2570
|
-
dbId,
|
|
2571
|
-
headers,
|
|
2572
|
-
params
|
|
2573
|
-
);
|
|
2208
|
+
return this.sessionManager.fetchSessions(config.endpoint, entityType, entityId, dbId, headers, params);
|
|
2574
2209
|
});
|
|
2575
2210
|
this.state.sessions = sessions;
|
|
2576
2211
|
this.emit("state:change", this.getState());
|
|
2577
2212
|
return sessions;
|
|
2578
2213
|
}
|
|
2579
|
-
/**
|
|
2580
|
-
* Delete a session
|
|
2581
|
-
*/
|
|
2582
2214
|
async deleteSession(sessionId, options) {
|
|
2583
2215
|
const config = this.configManager.getConfig();
|
|
2584
2216
|
const dbId = this.configManager.getDbId() || "";
|
|
2585
2217
|
const params = this.configManager.buildQueryString(options?.params);
|
|
2586
2218
|
await this.withTokenRefresh(() => {
|
|
2587
2219
|
const headers = this.configManager.buildRequestHeaders();
|
|
2588
|
-
return this.sessionManager.deleteSession(
|
|
2589
|
-
config.endpoint,
|
|
2590
|
-
sessionId,
|
|
2591
|
-
dbId,
|
|
2592
|
-
headers,
|
|
2593
|
-
params
|
|
2594
|
-
);
|
|
2220
|
+
return this.sessionManager.deleteSession(config.endpoint, sessionId, dbId, headers, params);
|
|
2595
2221
|
});
|
|
2596
|
-
this.state.sessions = this.state.sessions.filter(
|
|
2597
|
-
(s) => s.session_id !== sessionId
|
|
2598
|
-
);
|
|
2222
|
+
this.state.sessions = this.state.sessions.filter((s) => s.session_id !== sessionId);
|
|
2599
2223
|
if (this.configManager.getSessionId() === sessionId) {
|
|
2600
2224
|
this.clearMessages();
|
|
2601
2225
|
}
|
|
2602
2226
|
this.emit("session:deleted", { sessionId });
|
|
2603
2227
|
this.emit("state:change", this.getState());
|
|
2604
2228
|
}
|
|
2605
|
-
/**
|
|
2606
|
-
* Get a session by ID
|
|
2607
|
-
*/
|
|
2608
2229
|
async getSessionById(sessionId, options) {
|
|
2609
2230
|
const config = this.configManager.getConfig();
|
|
2610
2231
|
const entityType = this.configManager.getMode();
|
|
@@ -2613,20 +2234,9 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2613
2234
|
const params = this.configManager.buildQueryString(options?.params);
|
|
2614
2235
|
return await this.withTokenRefresh(() => {
|
|
2615
2236
|
const headers = this.configManager.buildRequestHeaders();
|
|
2616
|
-
return this.sessionManager.getSessionById(
|
|
2617
|
-
config.endpoint,
|
|
2618
|
-
entityType,
|
|
2619
|
-
sessionId,
|
|
2620
|
-
dbId,
|
|
2621
|
-
headers,
|
|
2622
|
-
userId,
|
|
2623
|
-
params
|
|
2624
|
-
);
|
|
2237
|
+
return this.sessionManager.getSessionById(config.endpoint, entityType, sessionId, dbId, headers, userId, params);
|
|
2625
2238
|
});
|
|
2626
2239
|
}
|
|
2627
|
-
/**
|
|
2628
|
-
* Get a run by ID
|
|
2629
|
-
*/
|
|
2630
2240
|
async getRunById(sessionId, runId, options) {
|
|
2631
2241
|
const config = this.configManager.getConfig();
|
|
2632
2242
|
const entityType = this.configManager.getMode();
|
|
@@ -2635,21 +2245,9 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2635
2245
|
const params = this.configManager.buildQueryString(options?.params);
|
|
2636
2246
|
return await this.withTokenRefresh(() => {
|
|
2637
2247
|
const headers = this.configManager.buildRequestHeaders();
|
|
2638
|
-
return this.sessionManager.getRunById(
|
|
2639
|
-
config.endpoint,
|
|
2640
|
-
entityType,
|
|
2641
|
-
sessionId,
|
|
2642
|
-
runId,
|
|
2643
|
-
dbId,
|
|
2644
|
-
headers,
|
|
2645
|
-
userId,
|
|
2646
|
-
params
|
|
2647
|
-
);
|
|
2248
|
+
return this.sessionManager.getRunById(config.endpoint, entityType, sessionId, runId, dbId, headers, userId, params);
|
|
2648
2249
|
});
|
|
2649
2250
|
}
|
|
2650
|
-
/**
|
|
2651
|
-
* Create a new session
|
|
2652
|
-
*/
|
|
2653
2251
|
async createSession(request, options) {
|
|
2654
2252
|
const config = this.configManager.getConfig();
|
|
2655
2253
|
const entityType = this.configManager.getMode();
|
|
@@ -2662,14 +2260,7 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2662
2260
|
const params = this.configManager.buildQueryString(options?.params);
|
|
2663
2261
|
const session = await this.withTokenRefresh(() => {
|
|
2664
2262
|
const headers = this.configManager.buildRequestHeaders();
|
|
2665
|
-
return this.sessionManager.createSession(
|
|
2666
|
-
config.endpoint,
|
|
2667
|
-
entityType,
|
|
2668
|
-
sessionRequest,
|
|
2669
|
-
dbId,
|
|
2670
|
-
headers,
|
|
2671
|
-
params
|
|
2672
|
-
);
|
|
2263
|
+
return this.sessionManager.createSession(config.endpoint, entityType, sessionRequest, dbId, headers, params);
|
|
2673
2264
|
});
|
|
2674
2265
|
const sessionEntry = {
|
|
2675
2266
|
session_id: session.session_id,
|
|
@@ -2682,9 +2273,6 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2682
2273
|
this.emit("state:change", this.getState());
|
|
2683
2274
|
return session;
|
|
2684
2275
|
}
|
|
2685
|
-
/**
|
|
2686
|
-
* Update a session
|
|
2687
|
-
*/
|
|
2688
2276
|
async updateSession(sessionId, request, options) {
|
|
2689
2277
|
const config = this.configManager.getConfig();
|
|
2690
2278
|
const entityType = this.configManager.getMode();
|
|
@@ -2693,31 +2281,17 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2693
2281
|
const params = this.configManager.buildQueryString(options?.params);
|
|
2694
2282
|
const session = await this.withTokenRefresh(() => {
|
|
2695
2283
|
const headers = this.configManager.buildRequestHeaders();
|
|
2696
|
-
return this.sessionManager.updateSession(
|
|
2697
|
-
config.endpoint,
|
|
2698
|
-
entityType,
|
|
2699
|
-
sessionId,
|
|
2700
|
-
request,
|
|
2701
|
-
dbId,
|
|
2702
|
-
headers,
|
|
2703
|
-
userId,
|
|
2704
|
-
params
|
|
2705
|
-
);
|
|
2284
|
+
return this.sessionManager.updateSession(config.endpoint, entityType, sessionId, request, dbId, headers, userId, params);
|
|
2706
2285
|
});
|
|
2707
|
-
this.state.sessions = this.state.sessions.map(
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
} : s
|
|
2713
|
-
);
|
|
2286
|
+
this.state.sessions = this.state.sessions.map((s) => s.session_id === sessionId ? {
|
|
2287
|
+
...s,
|
|
2288
|
+
session_name: session.session_name,
|
|
2289
|
+
updated_at: session.updated_at || s.updated_at
|
|
2290
|
+
} : s);
|
|
2714
2291
|
this.emit("session:updated", session);
|
|
2715
2292
|
this.emit("state:change", this.getState());
|
|
2716
2293
|
return session;
|
|
2717
2294
|
}
|
|
2718
|
-
/**
|
|
2719
|
-
* Rename a session
|
|
2720
|
-
*/
|
|
2721
2295
|
async renameSession(sessionId, newName, options) {
|
|
2722
2296
|
const config = this.configManager.getConfig();
|
|
2723
2297
|
const entityType = this.configManager.getMode();
|
|
@@ -2725,30 +2299,17 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2725
2299
|
const params = this.configManager.buildQueryString(options?.params);
|
|
2726
2300
|
const session = await this.withTokenRefresh(() => {
|
|
2727
2301
|
const headers = this.configManager.buildRequestHeaders();
|
|
2728
|
-
return this.sessionManager.renameSession(
|
|
2729
|
-
config.endpoint,
|
|
2730
|
-
entityType,
|
|
2731
|
-
sessionId,
|
|
2732
|
-
newName,
|
|
2733
|
-
dbId,
|
|
2734
|
-
headers,
|
|
2735
|
-
params
|
|
2736
|
-
);
|
|
2302
|
+
return this.sessionManager.renameSession(config.endpoint, entityType, sessionId, newName, dbId, headers, params);
|
|
2737
2303
|
});
|
|
2738
|
-
this.state.sessions = this.state.sessions.map(
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
} : s
|
|
2744
|
-
);
|
|
2304
|
+
this.state.sessions = this.state.sessions.map((s) => s.session_id === sessionId ? {
|
|
2305
|
+
...s,
|
|
2306
|
+
session_name: newName,
|
|
2307
|
+
updated_at: session.updated_at || s.updated_at
|
|
2308
|
+
} : s);
|
|
2745
2309
|
this.emit("session:renamed", { sessionId, newName, session });
|
|
2746
2310
|
this.emit("state:change", this.getState());
|
|
2747
2311
|
return session;
|
|
2748
2312
|
}
|
|
2749
|
-
/**
|
|
2750
|
-
* Delete multiple sessions
|
|
2751
|
-
*/
|
|
2752
2313
|
async deleteMultipleSessions(sessionIds, options) {
|
|
2753
2314
|
const config = this.configManager.getConfig();
|
|
2754
2315
|
const entityType = this.configManager.getMode();
|
|
@@ -2757,19 +2318,10 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2757
2318
|
const params = this.configManager.buildQueryString(options?.params);
|
|
2758
2319
|
await this.withTokenRefresh(() => {
|
|
2759
2320
|
const headers = this.configManager.buildRequestHeaders();
|
|
2760
|
-
return this.sessionManager.deleteMultipleSessions(
|
|
2761
|
-
config.endpoint,
|
|
2762
|
-
sessionIds,
|
|
2763
|
-
sessionTypes,
|
|
2764
|
-
dbId,
|
|
2765
|
-
headers,
|
|
2766
|
-
params
|
|
2767
|
-
);
|
|
2321
|
+
return this.sessionManager.deleteMultipleSessions(config.endpoint, sessionIds, sessionTypes, dbId, headers, params);
|
|
2768
2322
|
});
|
|
2769
2323
|
const deletedIds = new Set(sessionIds);
|
|
2770
|
-
this.state.sessions = this.state.sessions.filter(
|
|
2771
|
-
(s) => !deletedIds.has(s.session_id)
|
|
2772
|
-
);
|
|
2324
|
+
this.state.sessions = this.state.sessions.filter((s) => !deletedIds.has(s.session_id));
|
|
2773
2325
|
const currentSessionId = this.configManager.getSessionId();
|
|
2774
2326
|
if (currentSessionId && deletedIds.has(currentSessionId)) {
|
|
2775
2327
|
this.clearMessages();
|
|
@@ -2777,10 +2329,6 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2777
2329
|
this.emit("sessions:deleted", { sessionIds });
|
|
2778
2330
|
this.emit("state:change", this.getState());
|
|
2779
2331
|
}
|
|
2780
|
-
/**
|
|
2781
|
-
* Add tool calls to the last message
|
|
2782
|
-
* Used by frontend execution to add tool calls that were executed locally
|
|
2783
|
-
*/
|
|
2784
2332
|
addToolCallsToLastMessage(toolCalls) {
|
|
2785
2333
|
const lastMessage = this.messageStore.getLastMessage();
|
|
2786
2334
|
if (!lastMessage || lastMessage.role !== "agent") {
|
|
@@ -2797,18 +2345,12 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2797
2345
|
this.emit("message:update", this.messageStore.getMessages());
|
|
2798
2346
|
}
|
|
2799
2347
|
}
|
|
2800
|
-
/**
|
|
2801
|
-
* Hydrate a specific tool call with its UI component
|
|
2802
|
-
* If tool call doesn't exist yet, stores UI spec as pending
|
|
2803
|
-
*/
|
|
2804
2348
|
hydrateToolCallUI(toolCallId, uiSpec) {
|
|
2805
2349
|
const messages = this.messageStore.getMessages();
|
|
2806
|
-
for (let i = messages.length - 1;
|
|
2350
|
+
for (let i = messages.length - 1;i >= 0; i--) {
|
|
2807
2351
|
const message = messages[i];
|
|
2808
2352
|
if (message.tool_calls) {
|
|
2809
|
-
const toolIndex = message.tool_calls.findIndex(
|
|
2810
|
-
(t) => t.tool_call_id === toolCallId
|
|
2811
|
-
);
|
|
2353
|
+
const toolIndex = message.tool_calls.findIndex((t) => t.tool_call_id === toolCallId);
|
|
2812
2354
|
if (toolIndex !== -1) {
|
|
2813
2355
|
this.messageStore.updateMessage(i, (msg) => {
|
|
2814
2356
|
const updatedToolCalls = [...msg.tool_calls || []];
|
|
@@ -2829,21 +2371,17 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2829
2371
|
}
|
|
2830
2372
|
this.pendingUISpecs.set(toolCallId, uiSpec);
|
|
2831
2373
|
}
|
|
2832
|
-
/**
|
|
2833
|
-
* Apply any pending UI specs to tool calls that have just been added
|
|
2834
|
-
* Called after message updates to attach UI to newly arrived tool calls
|
|
2835
|
-
* Batches all updates to emit only one message:update event
|
|
2836
|
-
*/
|
|
2837
2374
|
applyPendingUISpecs() {
|
|
2838
|
-
if (this.pendingUISpecs.size === 0)
|
|
2375
|
+
if (this.pendingUISpecs.size === 0)
|
|
2376
|
+
return;
|
|
2839
2377
|
const messages = this.messageStore.getMessages();
|
|
2840
2378
|
const updatedMessages = [];
|
|
2841
|
-
for (let i = messages.length - 1;
|
|
2379
|
+
for (let i = messages.length - 1;i >= 0; i--) {
|
|
2842
2380
|
const message = messages[i];
|
|
2843
2381
|
if (message.tool_calls) {
|
|
2844
2382
|
let messageUpdated = false;
|
|
2845
2383
|
const updatedToolCalls = [...message.tool_calls];
|
|
2846
|
-
for (let j = 0;
|
|
2384
|
+
for (let j = 0;j < updatedToolCalls.length; j++) {
|
|
2847
2385
|
const toolCall = updatedToolCalls[j];
|
|
2848
2386
|
const pendingUI = this.pendingUISpecs.get(toolCall.tool_call_id);
|
|
2849
2387
|
if (pendingUI && !toolCall.ui_component) {
|
|
@@ -2873,24 +2411,9 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2873
2411
|
this.emit("message:update", this.messageStore.getMessages());
|
|
2874
2412
|
}
|
|
2875
2413
|
}
|
|
2876
|
-
/**
|
|
2877
|
-
* Continue a paused run with tool execution results.
|
|
2878
|
-
*
|
|
2879
|
-
* **Note:** HITL (Human-in-the-Loop) frontend tool execution is only supported for agents.
|
|
2880
|
-
* Teams do not support the continue endpoint.
|
|
2881
|
-
*
|
|
2882
|
-
* To cancel a running request, use the `cancelRun()` method.
|
|
2883
|
-
*
|
|
2884
|
-
* @param tools - Array of tool calls with execution results
|
|
2885
|
-
* @param options - Optional request headers and query parameters
|
|
2886
|
-
* @throws Error if no paused run exists
|
|
2887
|
-
* @throws Error if called with team mode (teams don't support HITL)
|
|
2888
|
-
*/
|
|
2889
2414
|
async continueRun(tools, options) {
|
|
2890
2415
|
if (this.configManager.getMode() === "team") {
|
|
2891
|
-
throw new Error(
|
|
2892
|
-
"HITL (Human-in-the-Loop) frontend tool execution is not supported for teams. Only agents support the continue endpoint."
|
|
2893
|
-
);
|
|
2416
|
+
throw new Error("HITL (Human-in-the-Loop) frontend tool execution is not supported for teams. " + "Only agents support the continue endpoint.");
|
|
2894
2417
|
}
|
|
2895
2418
|
if (!this.state.isPaused || !this.state.pausedRunId) {
|
|
2896
2419
|
throw new Error("No paused run to continue");
|
|
@@ -2900,7 +2423,7 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2900
2423
|
throw new Error("No agent or team selected");
|
|
2901
2424
|
}
|
|
2902
2425
|
const continueUrl = `${runUrl}/${this.state.pausedRunId}/continue`;
|
|
2903
|
-
this.abortController = new AbortController
|
|
2426
|
+
this.abortController = new AbortController;
|
|
2904
2427
|
this.state.isPaused = false;
|
|
2905
2428
|
this.state.isStreaming = true;
|
|
2906
2429
|
this.emit("run:continued", { runId: this.state.pausedRunId });
|
|
@@ -2909,7 +2432,7 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2909
2432
|
const { ui_component, ...backendTool } = tool;
|
|
2910
2433
|
return backendTool;
|
|
2911
2434
|
});
|
|
2912
|
-
const formData = new FormData
|
|
2435
|
+
const formData = new FormData;
|
|
2913
2436
|
formData.append("tools", JSON.stringify(cleanedTools));
|
|
2914
2437
|
formData.append("stream", "true");
|
|
2915
2438
|
const currentSessionId = this.configManager.getSessionId();
|
|
@@ -2934,11 +2457,11 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2934
2457
|
},
|
|
2935
2458
|
onComplete: async () => {
|
|
2936
2459
|
this.state.isStreaming = false;
|
|
2937
|
-
this.state.pausedRunId =
|
|
2938
|
-
this.state.toolsAwaitingExecution =
|
|
2939
|
-
this.currentRunId =
|
|
2940
|
-
this.state.currentRunId =
|
|
2941
|
-
this.abortController =
|
|
2460
|
+
this.state.pausedRunId = undefined;
|
|
2461
|
+
this.state.toolsAwaitingExecution = undefined;
|
|
2462
|
+
this.currentRunId = undefined;
|
|
2463
|
+
this.state.currentRunId = undefined;
|
|
2464
|
+
this.abortController = undefined;
|
|
2942
2465
|
this.emit("stream:end");
|
|
2943
2466
|
this.emit("message:complete", this.messageStore.getMessages());
|
|
2944
2467
|
this.emit("state:change", this.getState());
|
|
@@ -2949,9 +2472,6 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2949
2472
|
}
|
|
2950
2473
|
});
|
|
2951
2474
|
}
|
|
2952
|
-
/**
|
|
2953
|
-
* Check endpoint status
|
|
2954
|
-
*/
|
|
2955
2475
|
async checkStatus(options) {
|
|
2956
2476
|
try {
|
|
2957
2477
|
const params = this.configManager.buildQueryString(options?.params);
|
|
@@ -2972,9 +2492,6 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2972
2492
|
return false;
|
|
2973
2493
|
}
|
|
2974
2494
|
}
|
|
2975
|
-
/**
|
|
2976
|
-
* Fetch agents from endpoint
|
|
2977
|
-
*/
|
|
2978
2495
|
async fetchAgents(options) {
|
|
2979
2496
|
const params = this.configManager.buildQueryString(options?.params);
|
|
2980
2497
|
const url = new URL(`${this.configManager.getEndpoint()}/agents`);
|
|
@@ -2992,9 +2509,6 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
2992
2509
|
this.emit("state:change", this.getState());
|
|
2993
2510
|
return agents;
|
|
2994
2511
|
}
|
|
2995
|
-
/**
|
|
2996
|
-
* Fetch teams from endpoint
|
|
2997
|
-
*/
|
|
2998
2512
|
async fetchTeams(options) {
|
|
2999
2513
|
const params = this.configManager.buildQueryString(options?.params);
|
|
3000
2514
|
const url = new URL(`${this.configManager.getEndpoint()}/teams`);
|
|
@@ -3012,10 +2526,6 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
3012
2526
|
this.emit("state:change", this.getState());
|
|
3013
2527
|
return teams;
|
|
3014
2528
|
}
|
|
3015
|
-
/**
|
|
3016
|
-
* Initialize client (check status and fetch agents/teams)
|
|
3017
|
-
* Automatically selects the first available agent or team if none is configured
|
|
3018
|
-
*/
|
|
3019
2529
|
async initialize(options) {
|
|
3020
2530
|
const isActive = await this.checkStatus(options);
|
|
3021
2531
|
if (!isActive) {
|
|
@@ -3034,7 +2544,7 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
3034
2544
|
this.configManager.updateConfig({
|
|
3035
2545
|
mode: "agent",
|
|
3036
2546
|
agentId: firstAgent.id,
|
|
3037
|
-
dbId: firstAgent.db_id ||
|
|
2547
|
+
dbId: firstAgent.db_id || undefined
|
|
3038
2548
|
});
|
|
3039
2549
|
this.emit("config:change", this.configManager.getConfig());
|
|
3040
2550
|
} else if (teams.length > 0) {
|
|
@@ -3042,40 +2552,25 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
3042
2552
|
this.configManager.updateConfig({
|
|
3043
2553
|
mode: "team",
|
|
3044
2554
|
teamId: firstTeam.id,
|
|
3045
|
-
dbId: firstTeam.db_id ||
|
|
2555
|
+
dbId: firstTeam.db_id || undefined
|
|
3046
2556
|
});
|
|
3047
2557
|
this.emit("config:change", this.configManager.getConfig());
|
|
3048
2558
|
}
|
|
3049
2559
|
}
|
|
3050
2560
|
return { agents, teams };
|
|
3051
2561
|
}
|
|
3052
|
-
// ============================================================================
|
|
3053
|
-
// Memory Methods
|
|
3054
|
-
// ============================================================================
|
|
3055
|
-
/**
|
|
3056
|
-
* Fetch memories with optional filtering and pagination
|
|
3057
|
-
*/
|
|
3058
2562
|
async fetchMemories(queryParams, options) {
|
|
3059
2563
|
const config = this.configManager.getConfig();
|
|
3060
2564
|
const dbId = this.configManager.getDbId() || "";
|
|
3061
2565
|
const params = this.configManager.buildQueryString(options?.params);
|
|
3062
2566
|
const response = await this.withTokenRefresh(() => {
|
|
3063
2567
|
const headers = this.configManager.buildRequestHeaders();
|
|
3064
|
-
return this.memoryManager.fetchMemories(
|
|
3065
|
-
config.endpoint,
|
|
3066
|
-
dbId,
|
|
3067
|
-
headers,
|
|
3068
|
-
queryParams,
|
|
3069
|
-
params
|
|
3070
|
-
);
|
|
2568
|
+
return this.memoryManager.fetchMemories(config.endpoint, dbId, headers, queryParams, params);
|
|
3071
2569
|
});
|
|
3072
2570
|
this.state.memories = response.data;
|
|
3073
2571
|
this.emit("state:change", this.getState());
|
|
3074
2572
|
return response;
|
|
3075
2573
|
}
|
|
3076
|
-
/**
|
|
3077
|
-
* Get a specific memory by ID
|
|
3078
|
-
*/
|
|
3079
2574
|
async getMemoryById(memoryId, options) {
|
|
3080
2575
|
const config = this.configManager.getConfig();
|
|
3081
2576
|
const dbId = this.configManager.getDbId() || "";
|
|
@@ -3083,108 +2578,56 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
3083
2578
|
const params = this.configManager.buildQueryString(options?.params);
|
|
3084
2579
|
return await this.withTokenRefresh(() => {
|
|
3085
2580
|
const headers = this.configManager.buildRequestHeaders();
|
|
3086
|
-
return this.memoryManager.getMemoryById(
|
|
3087
|
-
config.endpoint,
|
|
3088
|
-
memoryId,
|
|
3089
|
-
dbId,
|
|
3090
|
-
headers,
|
|
3091
|
-
userId,
|
|
3092
|
-
options?.table,
|
|
3093
|
-
params
|
|
3094
|
-
);
|
|
2581
|
+
return this.memoryManager.getMemoryById(config.endpoint, memoryId, dbId, headers, userId, options?.table, params);
|
|
3095
2582
|
});
|
|
3096
2583
|
}
|
|
3097
|
-
/**
|
|
3098
|
-
* Get all available memory topics
|
|
3099
|
-
*/
|
|
3100
2584
|
async getMemoryTopics(options) {
|
|
3101
2585
|
const config = this.configManager.getConfig();
|
|
3102
2586
|
const dbId = this.configManager.getDbId() || "";
|
|
3103
2587
|
const params = this.configManager.buildQueryString(options?.params);
|
|
3104
2588
|
const topics = await this.withTokenRefresh(() => {
|
|
3105
2589
|
const headers = this.configManager.buildRequestHeaders();
|
|
3106
|
-
return this.memoryManager.getMemoryTopics(
|
|
3107
|
-
config.endpoint,
|
|
3108
|
-
dbId,
|
|
3109
|
-
headers,
|
|
3110
|
-
options?.table,
|
|
3111
|
-
params
|
|
3112
|
-
);
|
|
2590
|
+
return this.memoryManager.getMemoryTopics(config.endpoint, dbId, headers, options?.table, params);
|
|
3113
2591
|
});
|
|
3114
2592
|
this.state.memoryTopics = topics;
|
|
3115
2593
|
this.emit("state:change", this.getState());
|
|
3116
2594
|
return topics;
|
|
3117
2595
|
}
|
|
3118
|
-
/**
|
|
3119
|
-
* Get user memory statistics
|
|
3120
|
-
*/
|
|
3121
2596
|
async getUserMemoryStats(queryParams, options) {
|
|
3122
2597
|
const config = this.configManager.getConfig();
|
|
3123
2598
|
const dbId = this.configManager.getDbId() || "";
|
|
3124
2599
|
const params = this.configManager.buildQueryString(options?.params);
|
|
3125
2600
|
return await this.withTokenRefresh(() => {
|
|
3126
2601
|
const headers = this.configManager.buildRequestHeaders();
|
|
3127
|
-
return this.memoryManager.getUserMemoryStats(
|
|
3128
|
-
config.endpoint,
|
|
3129
|
-
dbId,
|
|
3130
|
-
headers,
|
|
3131
|
-
queryParams,
|
|
3132
|
-
params
|
|
3133
|
-
);
|
|
2602
|
+
return this.memoryManager.getUserMemoryStats(config.endpoint, dbId, headers, queryParams, params);
|
|
3134
2603
|
});
|
|
3135
2604
|
}
|
|
3136
|
-
/**
|
|
3137
|
-
* Create a new memory
|
|
3138
|
-
*/
|
|
3139
2605
|
async createMemory(request, options) {
|
|
3140
2606
|
const config = this.configManager.getConfig();
|
|
3141
2607
|
const dbId = this.configManager.getDbId() || "";
|
|
3142
2608
|
const params = this.configManager.buildQueryString(options?.params);
|
|
3143
2609
|
const memory = await this.withTokenRefresh(() => {
|
|
3144
2610
|
const headers = this.configManager.buildRequestHeaders();
|
|
3145
|
-
return this.memoryManager.createMemory(
|
|
3146
|
-
config.endpoint,
|
|
3147
|
-
request,
|
|
3148
|
-
dbId,
|
|
3149
|
-
headers,
|
|
3150
|
-
options?.table,
|
|
3151
|
-
params
|
|
3152
|
-
);
|
|
2611
|
+
return this.memoryManager.createMemory(config.endpoint, request, dbId, headers, options?.table, params);
|
|
3153
2612
|
});
|
|
3154
2613
|
this.state.memories = [memory, ...this.state.memories];
|
|
3155
2614
|
this.emit("memory:created", memory);
|
|
3156
2615
|
this.emit("state:change", this.getState());
|
|
3157
2616
|
return memory;
|
|
3158
2617
|
}
|
|
3159
|
-
/**
|
|
3160
|
-
* Update an existing memory
|
|
3161
|
-
*/
|
|
3162
2618
|
async updateMemory(memoryId, request, options) {
|
|
3163
2619
|
const config = this.configManager.getConfig();
|
|
3164
2620
|
const dbId = this.configManager.getDbId() || "";
|
|
3165
2621
|
const params = this.configManager.buildQueryString(options?.params);
|
|
3166
2622
|
const memory = await this.withTokenRefresh(() => {
|
|
3167
2623
|
const headers = this.configManager.buildRequestHeaders();
|
|
3168
|
-
return this.memoryManager.updateMemory(
|
|
3169
|
-
config.endpoint,
|
|
3170
|
-
memoryId,
|
|
3171
|
-
request,
|
|
3172
|
-
dbId,
|
|
3173
|
-
headers,
|
|
3174
|
-
options?.table,
|
|
3175
|
-
params
|
|
3176
|
-
);
|
|
2624
|
+
return this.memoryManager.updateMemory(config.endpoint, memoryId, request, dbId, headers, options?.table, params);
|
|
3177
2625
|
});
|
|
3178
|
-
this.state.memories = this.state.memories.map(
|
|
3179
|
-
(m) => m.memory_id === memoryId ? memory : m
|
|
3180
|
-
);
|
|
2626
|
+
this.state.memories = this.state.memories.map((m) => m.memory_id === memoryId ? memory : m);
|
|
3181
2627
|
this.emit("memory:updated", memory);
|
|
3182
2628
|
this.emit("state:change", this.getState());
|
|
3183
2629
|
return memory;
|
|
3184
2630
|
}
|
|
3185
|
-
/**
|
|
3186
|
-
* Delete a single memory
|
|
3187
|
-
*/
|
|
3188
2631
|
async deleteMemory(memoryId, options) {
|
|
3189
2632
|
const config = this.configManager.getConfig();
|
|
3190
2633
|
const dbId = this.configManager.getDbId() || "";
|
|
@@ -3192,25 +2635,12 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
3192
2635
|
const params = this.configManager.buildQueryString(options?.params);
|
|
3193
2636
|
await this.withTokenRefresh(() => {
|
|
3194
2637
|
const headers = this.configManager.buildRequestHeaders();
|
|
3195
|
-
return this.memoryManager.deleteMemory(
|
|
3196
|
-
config.endpoint,
|
|
3197
|
-
memoryId,
|
|
3198
|
-
dbId,
|
|
3199
|
-
headers,
|
|
3200
|
-
userId,
|
|
3201
|
-
options?.table,
|
|
3202
|
-
params
|
|
3203
|
-
);
|
|
2638
|
+
return this.memoryManager.deleteMemory(config.endpoint, memoryId, dbId, headers, userId, options?.table, params);
|
|
3204
2639
|
});
|
|
3205
|
-
this.state.memories = this.state.memories.filter(
|
|
3206
|
-
(m) => m.memory_id !== memoryId
|
|
3207
|
-
);
|
|
2640
|
+
this.state.memories = this.state.memories.filter((m) => m.memory_id !== memoryId);
|
|
3208
2641
|
this.emit("memory:deleted", { memoryId });
|
|
3209
2642
|
this.emit("state:change", this.getState());
|
|
3210
2643
|
}
|
|
3211
|
-
/**
|
|
3212
|
-
* Delete multiple memories
|
|
3213
|
-
*/
|
|
3214
2644
|
async deleteMultipleMemories(memoryIds, options) {
|
|
3215
2645
|
const config = this.configManager.getConfig();
|
|
3216
2646
|
const dbId = this.configManager.getDbId() || "";
|
|
@@ -3221,94 +2651,45 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
3221
2651
|
};
|
|
3222
2652
|
await this.withTokenRefresh(() => {
|
|
3223
2653
|
const headers = this.configManager.buildRequestHeaders();
|
|
3224
|
-
return this.memoryManager.deleteMultipleMemories(
|
|
3225
|
-
config.endpoint,
|
|
3226
|
-
request,
|
|
3227
|
-
dbId,
|
|
3228
|
-
headers,
|
|
3229
|
-
options?.table,
|
|
3230
|
-
params
|
|
3231
|
-
);
|
|
2654
|
+
return this.memoryManager.deleteMultipleMemories(config.endpoint, request, dbId, headers, options?.table, params);
|
|
3232
2655
|
});
|
|
3233
2656
|
const deletedIds = new Set(memoryIds);
|
|
3234
|
-
this.state.memories = this.state.memories.filter(
|
|
3235
|
-
(m) => !deletedIds.has(m.memory_id)
|
|
3236
|
-
);
|
|
2657
|
+
this.state.memories = this.state.memories.filter((m) => !deletedIds.has(m.memory_id));
|
|
3237
2658
|
this.emit("memories:deleted", { memoryIds });
|
|
3238
2659
|
this.emit("state:change", this.getState());
|
|
3239
2660
|
}
|
|
3240
|
-
// ============================================================================
|
|
3241
|
-
// Knowledge API Methods
|
|
3242
|
-
// ============================================================================
|
|
3243
|
-
/**
|
|
3244
|
-
* Get knowledge configuration
|
|
3245
|
-
*/
|
|
3246
2661
|
async getKnowledgeConfig(options) {
|
|
3247
2662
|
const config = this.configManager.getConfig();
|
|
3248
2663
|
const params = this.configManager.buildQueryString(options?.params);
|
|
3249
2664
|
return await this.withTokenRefresh(() => {
|
|
3250
2665
|
const headers = this.configManager.buildRequestHeaders();
|
|
3251
|
-
return this.knowledgeManager.getConfig(
|
|
3252
|
-
config.endpoint,
|
|
3253
|
-
headers,
|
|
3254
|
-
options?.dbId ?? this.configManager.getDbId(),
|
|
3255
|
-
params
|
|
3256
|
-
);
|
|
2666
|
+
return this.knowledgeManager.getConfig(config.endpoint, headers, options?.dbId ?? this.configManager.getDbId(), params);
|
|
3257
2667
|
});
|
|
3258
2668
|
}
|
|
3259
|
-
/**
|
|
3260
|
-
* List knowledge content
|
|
3261
|
-
*/
|
|
3262
2669
|
async listKnowledgeContent(listOptions, options) {
|
|
3263
2670
|
const config = this.configManager.getConfig();
|
|
3264
2671
|
const params = this.configManager.buildQueryString(options?.params);
|
|
3265
2672
|
return await this.withTokenRefresh(() => {
|
|
3266
2673
|
const headers = this.configManager.buildRequestHeaders();
|
|
3267
|
-
return this.knowledgeManager.listContent(
|
|
3268
|
-
config.endpoint,
|
|
3269
|
-
headers,
|
|
3270
|
-
listOptions,
|
|
3271
|
-
params
|
|
3272
|
-
);
|
|
2674
|
+
return this.knowledgeManager.listContent(config.endpoint, headers, listOptions, params);
|
|
3273
2675
|
});
|
|
3274
2676
|
}
|
|
3275
|
-
/**
|
|
3276
|
-
* Get knowledge content by ID
|
|
3277
|
-
*/
|
|
3278
2677
|
async getKnowledgeContent(contentId, options) {
|
|
3279
2678
|
const config = this.configManager.getConfig();
|
|
3280
2679
|
const params = this.configManager.buildQueryString(options?.params);
|
|
3281
2680
|
return await this.withTokenRefresh(() => {
|
|
3282
2681
|
const headers = this.configManager.buildRequestHeaders();
|
|
3283
|
-
return this.knowledgeManager.getContent(
|
|
3284
|
-
config.endpoint,
|
|
3285
|
-
contentId,
|
|
3286
|
-
headers,
|
|
3287
|
-
options?.dbId ?? this.configManager.getDbId(),
|
|
3288
|
-
params
|
|
3289
|
-
);
|
|
2682
|
+
return this.knowledgeManager.getContent(config.endpoint, contentId, headers, options?.dbId ?? this.configManager.getDbId(), params);
|
|
3290
2683
|
});
|
|
3291
2684
|
}
|
|
3292
|
-
/**
|
|
3293
|
-
* Get knowledge content status
|
|
3294
|
-
*/
|
|
3295
2685
|
async getKnowledgeContentStatus(contentId, options) {
|
|
3296
2686
|
const config = this.configManager.getConfig();
|
|
3297
2687
|
const params = this.configManager.buildQueryString(options?.params);
|
|
3298
2688
|
return await this.withTokenRefresh(() => {
|
|
3299
2689
|
const headers = this.configManager.buildRequestHeaders();
|
|
3300
|
-
return this.knowledgeManager.getContentStatus(
|
|
3301
|
-
config.endpoint,
|
|
3302
|
-
contentId,
|
|
3303
|
-
headers,
|
|
3304
|
-
options?.dbId ?? this.configManager.getDbId(),
|
|
3305
|
-
params
|
|
3306
|
-
);
|
|
2690
|
+
return this.knowledgeManager.getContentStatus(config.endpoint, contentId, headers, options?.dbId ?? this.configManager.getDbId(), params);
|
|
3307
2691
|
});
|
|
3308
2692
|
}
|
|
3309
|
-
/**
|
|
3310
|
-
* Search knowledge base
|
|
3311
|
-
*/
|
|
3312
2693
|
async searchKnowledge(request, options) {
|
|
3313
2694
|
const config = this.configManager.getConfig();
|
|
3314
2695
|
const params = this.configManager.buildQueryString(options?.params);
|
|
@@ -3318,18 +2699,9 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
3318
2699
|
};
|
|
3319
2700
|
return await this.withTokenRefresh(() => {
|
|
3320
2701
|
const headers = this.configManager.buildRequestHeaders();
|
|
3321
|
-
return this.knowledgeManager.search(
|
|
3322
|
-
config.endpoint,
|
|
3323
|
-
searchRequest,
|
|
3324
|
-
headers,
|
|
3325
|
-
params
|
|
3326
|
-
);
|
|
2702
|
+
return this.knowledgeManager.search(config.endpoint, searchRequest, headers, params);
|
|
3327
2703
|
});
|
|
3328
2704
|
}
|
|
3329
|
-
/**
|
|
3330
|
-
* Upload knowledge content
|
|
3331
|
-
* @param data - FormData with file/text_content or ContentUploadRequest object
|
|
3332
|
-
*/
|
|
3333
2705
|
async uploadKnowledgeContent(data, options) {
|
|
3334
2706
|
const config = this.configManager.getConfig();
|
|
3335
2707
|
const params = this.configManager.buildQueryString(options?.params);
|
|
@@ -3337,91 +2709,57 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
3337
2709
|
if (data instanceof FormData) {
|
|
3338
2710
|
formData = data;
|
|
3339
2711
|
} else {
|
|
3340
|
-
formData = new FormData
|
|
3341
|
-
if (data.name)
|
|
3342
|
-
|
|
3343
|
-
if (data.
|
|
3344
|
-
|
|
3345
|
-
if (data.
|
|
3346
|
-
|
|
3347
|
-
if (data.
|
|
3348
|
-
|
|
3349
|
-
if (data.
|
|
2712
|
+
formData = new FormData;
|
|
2713
|
+
if (data.name)
|
|
2714
|
+
formData.append("name", data.name);
|
|
2715
|
+
if (data.description)
|
|
2716
|
+
formData.append("description", data.description);
|
|
2717
|
+
if (data.url)
|
|
2718
|
+
formData.append("url", data.url);
|
|
2719
|
+
if (data.metadata)
|
|
2720
|
+
formData.append("metadata", JSON.stringify(data.metadata));
|
|
2721
|
+
if (data.file)
|
|
2722
|
+
formData.append("file", data.file);
|
|
2723
|
+
if (data.text_content)
|
|
2724
|
+
formData.append("text_content", data.text_content);
|
|
2725
|
+
if (data.reader_id)
|
|
2726
|
+
formData.append("reader_id", data.reader_id);
|
|
2727
|
+
if (data.chunker)
|
|
2728
|
+
formData.append("chunker", data.chunker);
|
|
2729
|
+
if (data.chunk_size !== undefined)
|
|
3350
2730
|
formData.append("chunk_size", String(data.chunk_size));
|
|
3351
|
-
if (data.chunk_overlap !==
|
|
2731
|
+
if (data.chunk_overlap !== undefined)
|
|
3352
2732
|
formData.append("chunk_overlap", String(data.chunk_overlap));
|
|
3353
2733
|
}
|
|
3354
2734
|
return await this.withTokenRefresh(() => {
|
|
3355
2735
|
const headers = this.configManager.buildRequestHeaders();
|
|
3356
|
-
return this.knowledgeManager.uploadContent(
|
|
3357
|
-
config.endpoint,
|
|
3358
|
-
formData,
|
|
3359
|
-
headers,
|
|
3360
|
-
options?.dbId ?? this.configManager.getDbId(),
|
|
3361
|
-
params
|
|
3362
|
-
);
|
|
2736
|
+
return this.knowledgeManager.uploadContent(config.endpoint, formData, headers, options?.dbId ?? this.configManager.getDbId(), params);
|
|
3363
2737
|
});
|
|
3364
2738
|
}
|
|
3365
|
-
/**
|
|
3366
|
-
* Update knowledge content
|
|
3367
|
-
*/
|
|
3368
2739
|
async updateKnowledgeContent(contentId, request, options) {
|
|
3369
2740
|
const config = this.configManager.getConfig();
|
|
3370
2741
|
const params = this.configManager.buildQueryString(options?.params);
|
|
3371
2742
|
return await this.withTokenRefresh(() => {
|
|
3372
2743
|
const headers = this.configManager.buildRequestHeaders();
|
|
3373
|
-
return this.knowledgeManager.updateContent(
|
|
3374
|
-
config.endpoint,
|
|
3375
|
-
contentId,
|
|
3376
|
-
request,
|
|
3377
|
-
headers,
|
|
3378
|
-
options?.dbId ?? this.configManager.getDbId(),
|
|
3379
|
-
params
|
|
3380
|
-
);
|
|
2744
|
+
return this.knowledgeManager.updateContent(config.endpoint, contentId, request, headers, options?.dbId ?? this.configManager.getDbId(), params);
|
|
3381
2745
|
});
|
|
3382
2746
|
}
|
|
3383
|
-
/**
|
|
3384
|
-
* Delete all knowledge content
|
|
3385
|
-
*/
|
|
3386
2747
|
async deleteAllKnowledgeContent(options) {
|
|
3387
2748
|
const config = this.configManager.getConfig();
|
|
3388
2749
|
const params = this.configManager.buildQueryString(options?.params);
|
|
3389
2750
|
await this.withTokenRefresh(() => {
|
|
3390
2751
|
const headers = this.configManager.buildRequestHeaders();
|
|
3391
|
-
return this.knowledgeManager.deleteAllContent(
|
|
3392
|
-
config.endpoint,
|
|
3393
|
-
headers,
|
|
3394
|
-
options?.dbId ?? this.configManager.getDbId(),
|
|
3395
|
-
params
|
|
3396
|
-
);
|
|
2752
|
+
return this.knowledgeManager.deleteAllContent(config.endpoint, headers, options?.dbId ?? this.configManager.getDbId(), params);
|
|
3397
2753
|
});
|
|
3398
2754
|
}
|
|
3399
|
-
/**
|
|
3400
|
-
* Delete knowledge content by ID
|
|
3401
|
-
*/
|
|
3402
2755
|
async deleteKnowledgeContent(contentId, options) {
|
|
3403
2756
|
const config = this.configManager.getConfig();
|
|
3404
2757
|
const params = this.configManager.buildQueryString(options?.params);
|
|
3405
2758
|
return await this.withTokenRefresh(() => {
|
|
3406
2759
|
const headers = this.configManager.buildRequestHeaders();
|
|
3407
|
-
return this.knowledgeManager.deleteContent(
|
|
3408
|
-
config.endpoint,
|
|
3409
|
-
contentId,
|
|
3410
|
-
headers,
|
|
3411
|
-
options?.dbId ?? this.configManager.getDbId(),
|
|
3412
|
-
params
|
|
3413
|
-
);
|
|
2760
|
+
return this.knowledgeManager.deleteContent(config.endpoint, contentId, headers, options?.dbId ?? this.configManager.getDbId(), params);
|
|
3414
2761
|
});
|
|
3415
2762
|
}
|
|
3416
|
-
// ============================================================================
|
|
3417
|
-
// Metrics API Methods
|
|
3418
|
-
// ============================================================================
|
|
3419
|
-
/**
|
|
3420
|
-
* Fetch aggregated metrics from the endpoint
|
|
3421
|
-
*
|
|
3422
|
-
* @param options - Options including date range, dbId, table, and custom params
|
|
3423
|
-
* @returns MetricsResponse containing daily aggregated metrics
|
|
3424
|
-
*/
|
|
3425
2763
|
async fetchMetrics(options) {
|
|
3426
2764
|
const url = new URL(`${this.configManager.getEndpoint()}/metrics`);
|
|
3427
2765
|
const params = this.configManager.buildQueryString(options?.params);
|
|
@@ -3450,12 +2788,6 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
3450
2788
|
const metrics = await response.json();
|
|
3451
2789
|
return metrics;
|
|
3452
2790
|
}
|
|
3453
|
-
/**
|
|
3454
|
-
* Refresh/recalculate metrics on the backend
|
|
3455
|
-
*
|
|
3456
|
-
* @param options - Options including dbId, table, and custom params
|
|
3457
|
-
* @returns Array of refreshed DayAggregatedMetrics
|
|
3458
|
-
*/
|
|
3459
2791
|
async refreshMetrics(options) {
|
|
3460
2792
|
const url = new URL(`${this.configManager.getEndpoint()}/metrics/refresh`);
|
|
3461
2793
|
const params = this.configManager.buildQueryString(options?.params);
|
|
@@ -3480,120 +2812,46 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
3480
2812
|
const metrics = await response.json();
|
|
3481
2813
|
return metrics;
|
|
3482
2814
|
}
|
|
3483
|
-
// ============================================================================
|
|
3484
|
-
// Evaluation Methods
|
|
3485
|
-
// ============================================================================
|
|
3486
|
-
/**
|
|
3487
|
-
* List evaluation runs with optional filtering and pagination
|
|
3488
|
-
* @param listParams - Parameters for filtering and pagination
|
|
3489
|
-
* @param options - Optional request query parameters
|
|
3490
|
-
*/
|
|
3491
2815
|
async listEvalRuns(listParams = {}, options) {
|
|
3492
2816
|
const additionalParams = this.configManager.buildQueryString(options?.params);
|
|
3493
2817
|
return await this.withTokenRefresh(() => {
|
|
3494
2818
|
const headers = this.configManager.buildRequestHeaders();
|
|
3495
|
-
return this.evalManager.listEvalRuns(
|
|
3496
|
-
this.configManager.getEndpoint(),
|
|
3497
|
-
listParams,
|
|
3498
|
-
headers,
|
|
3499
|
-
additionalParams
|
|
3500
|
-
);
|
|
2819
|
+
return this.evalManager.listEvalRuns(this.configManager.getEndpoint(), listParams, headers, additionalParams);
|
|
3501
2820
|
});
|
|
3502
2821
|
}
|
|
3503
|
-
/**
|
|
3504
|
-
* Get a specific evaluation run by ID
|
|
3505
|
-
* @param evalRunId - The evaluation run ID
|
|
3506
|
-
* @param options - Optional db_id, table, and query parameters
|
|
3507
|
-
*/
|
|
3508
2822
|
async getEvalRun(evalRunId, options) {
|
|
3509
2823
|
const additionalParams = this.configManager.buildQueryString(options?.params);
|
|
3510
2824
|
return await this.withTokenRefresh(() => {
|
|
3511
2825
|
const headers = this.configManager.buildRequestHeaders();
|
|
3512
|
-
return this.evalManager.getEvalRun(
|
|
3513
|
-
this.configManager.getEndpoint(),
|
|
3514
|
-
evalRunId,
|
|
3515
|
-
options?.dbId,
|
|
3516
|
-
options?.table,
|
|
3517
|
-
headers,
|
|
3518
|
-
additionalParams
|
|
3519
|
-
);
|
|
2826
|
+
return this.evalManager.getEvalRun(this.configManager.getEndpoint(), evalRunId, options?.dbId, options?.table, headers, additionalParams);
|
|
3520
2827
|
});
|
|
3521
2828
|
}
|
|
3522
|
-
/**
|
|
3523
|
-
* Execute a new evaluation
|
|
3524
|
-
* @param request - The evaluation request parameters
|
|
3525
|
-
* @param options - Optional db_id, table, and query parameters
|
|
3526
|
-
*/
|
|
3527
2829
|
async executeEval(request, options) {
|
|
3528
2830
|
const additionalParams = this.configManager.buildQueryString(options?.params);
|
|
3529
2831
|
const result = await this.withTokenRefresh(() => {
|
|
3530
2832
|
const headers = this.configManager.buildRequestHeaders();
|
|
3531
|
-
return this.evalManager.executeEval(
|
|
3532
|
-
this.configManager.getEndpoint(),
|
|
3533
|
-
request,
|
|
3534
|
-
options?.dbId,
|
|
3535
|
-
options?.table,
|
|
3536
|
-
headers,
|
|
3537
|
-
additionalParams
|
|
3538
|
-
);
|
|
2833
|
+
return this.evalManager.executeEval(this.configManager.getEndpoint(), request, options?.dbId, options?.table, headers, additionalParams);
|
|
3539
2834
|
});
|
|
3540
2835
|
this.emit("eval:executed", result);
|
|
3541
2836
|
return result;
|
|
3542
2837
|
}
|
|
3543
|
-
/**
|
|
3544
|
-
* Update an evaluation run (rename)
|
|
3545
|
-
* @param evalRunId - The evaluation run ID
|
|
3546
|
-
* @param request - The update request with new name
|
|
3547
|
-
* @param options - Optional db_id, table, and query parameters
|
|
3548
|
-
*/
|
|
3549
2838
|
async updateEvalRun(evalRunId, request, options) {
|
|
3550
2839
|
const additionalParams = this.configManager.buildQueryString(options?.params);
|
|
3551
2840
|
const result = await this.withTokenRefresh(() => {
|
|
3552
2841
|
const headers = this.configManager.buildRequestHeaders();
|
|
3553
|
-
return this.evalManager.updateEvalRun(
|
|
3554
|
-
this.configManager.getEndpoint(),
|
|
3555
|
-
evalRunId,
|
|
3556
|
-
request,
|
|
3557
|
-
options?.dbId,
|
|
3558
|
-
options?.table,
|
|
3559
|
-
headers,
|
|
3560
|
-
additionalParams
|
|
3561
|
-
);
|
|
2842
|
+
return this.evalManager.updateEvalRun(this.configManager.getEndpoint(), evalRunId, request, options?.dbId, options?.table, headers, additionalParams);
|
|
3562
2843
|
});
|
|
3563
2844
|
this.emit("eval:updated", result);
|
|
3564
2845
|
return result;
|
|
3565
2846
|
}
|
|
3566
|
-
/**
|
|
3567
|
-
* Delete multiple evaluation runs
|
|
3568
|
-
* @param evalRunIds - Array of evaluation run IDs to delete
|
|
3569
|
-
* @param options - Optional db_id, table, and query parameters
|
|
3570
|
-
*/
|
|
3571
2847
|
async deleteEvalRuns(evalRunIds, options) {
|
|
3572
2848
|
const additionalParams = this.configManager.buildQueryString(options?.params);
|
|
3573
2849
|
await this.withTokenRefresh(() => {
|
|
3574
2850
|
const headers = this.configManager.buildRequestHeaders();
|
|
3575
|
-
return this.evalManager.deleteEvalRuns(
|
|
3576
|
-
this.configManager.getEndpoint(),
|
|
3577
|
-
{ eval_run_ids: evalRunIds },
|
|
3578
|
-
options?.dbId,
|
|
3579
|
-
options?.table,
|
|
3580
|
-
headers,
|
|
3581
|
-
additionalParams
|
|
3582
|
-
);
|
|
2851
|
+
return this.evalManager.deleteEvalRuns(this.configManager.getEndpoint(), { eval_run_ids: evalRunIds }, options?.dbId, options?.table, headers, additionalParams);
|
|
3583
2852
|
});
|
|
3584
2853
|
this.emit("evals:deleted", { evalRunIds });
|
|
3585
2854
|
}
|
|
3586
|
-
// =============================================================================
|
|
3587
|
-
// TRACES API METHODS
|
|
3588
|
-
// =============================================================================
|
|
3589
|
-
/**
|
|
3590
|
-
* Fetch traces with optional filters
|
|
3591
|
-
* GET /traces
|
|
3592
|
-
*
|
|
3593
|
-
* @param options - Filter and pagination options
|
|
3594
|
-
* @param requestOptions - Optional per-request headers and params
|
|
3595
|
-
* @returns Paginated traces result with traces and pagination info
|
|
3596
|
-
*/
|
|
3597
2855
|
async fetchTraces(options = {}, requestOptions) {
|
|
3598
2856
|
const config = this.configManager.getConfig();
|
|
3599
2857
|
const dbId = this.configManager.getDbId();
|
|
@@ -3610,15 +2868,6 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
3610
2868
|
this.emit("state:change", this.getState());
|
|
3611
2869
|
return result;
|
|
3612
2870
|
}
|
|
3613
|
-
/**
|
|
3614
|
-
* Get trace detail or a specific span
|
|
3615
|
-
* GET /traces/{trace_id}
|
|
3616
|
-
*
|
|
3617
|
-
* @param traceId - The trace ID to fetch
|
|
3618
|
-
* @param options - Options including optional span_id, run_id, db_id
|
|
3619
|
-
* @param requestOptions - Optional per-request headers and params
|
|
3620
|
-
* @returns TraceDetail (full trace) or TraceNode (specific span)
|
|
3621
|
-
*/
|
|
3622
2871
|
async getTraceDetail(traceId, options = {}, requestOptions) {
|
|
3623
2872
|
const config = this.configManager.getConfig();
|
|
3624
2873
|
const dbId = this.configManager.getDbId();
|
|
@@ -3632,14 +2881,6 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
3632
2881
|
return this.tracesManager.getTraceDetail(config.endpoint, traceId, traceOptions, headers, params);
|
|
3633
2882
|
});
|
|
3634
2883
|
}
|
|
3635
|
-
/**
|
|
3636
|
-
* Get trace session statistics
|
|
3637
|
-
* GET /trace_session_stats
|
|
3638
|
-
*
|
|
3639
|
-
* @param options - Filter and pagination options
|
|
3640
|
-
* @param requestOptions - Optional per-request headers and params
|
|
3641
|
-
* @returns Paginated trace session stats result
|
|
3642
|
-
*/
|
|
3643
2884
|
async fetchTraceSessionStats(options = {}, requestOptions) {
|
|
3644
2885
|
const config = this.configManager.getConfig();
|
|
3645
2886
|
const dbId = this.configManager.getDbId();
|
|
@@ -3656,13 +2897,9 @@ var AgnoClient = class extends import_eventemitter3.default {
|
|
|
3656
2897
|
this.emit("state:change", this.getState());
|
|
3657
2898
|
return result;
|
|
3658
2899
|
}
|
|
3659
|
-
}
|
|
2900
|
+
}
|
|
3660
2901
|
|
|
3661
2902
|
// src/index.ts
|
|
3662
2903
|
var import_agno_types3 = require("@rodrigocoliveira/agno-types");
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
AgnoClient,
|
|
3666
|
-
Logger,
|
|
3667
|
-
RunEvent
|
|
3668
|
-
});
|
|
2904
|
+
|
|
2905
|
+
//# debugId=D5019D5FEEAE9C2664756E2164756E21
|