@antipopp/agno-client 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -238,6 +238,18 @@ var ConfigManager = class {
238
238
  setUserId(userId) {
239
239
  this.updateField("userId", userId);
240
240
  }
241
+ /**
242
+ * Get custom headers
243
+ */
244
+ getHeaders() {
245
+ return this.config.headers;
246
+ }
247
+ /**
248
+ * Set custom headers
249
+ */
250
+ setHeaders(headers) {
251
+ this.updateField("headers", headers);
252
+ }
241
253
  /**
242
254
  * Get current entity ID (agent or team based on mode)
243
255
  */
@@ -260,6 +272,31 @@ var ConfigManager = class {
260
272
  return `${endpoint}/agents/${encodedEntityId}/runs`;
261
273
  }
262
274
  }
275
+ /**
276
+ * Build request headers by merging global headers, per-request headers, and auth token.
277
+ * Merge order (lowest to highest precedence):
278
+ * 1. Global headers from config
279
+ * 2. Per-request headers (overrides global)
280
+ * 3. Authorization header from authToken (overrides all)
281
+ *
282
+ * @param perRequestHeaders - Optional headers for this specific request
283
+ * @returns Merged headers object ready for fetch
284
+ */
285
+ buildRequestHeaders(perRequestHeaders) {
286
+ const headers = {};
287
+ const globalHeaders = this.getHeaders();
288
+ if (globalHeaders) {
289
+ Object.assign(headers, globalHeaders);
290
+ }
291
+ if (perRequestHeaders) {
292
+ Object.assign(headers, perRequestHeaders);
293
+ }
294
+ const authToken = this.getAuthToken();
295
+ if (authToken) {
296
+ headers["Authorization"] = `Bearer ${authToken}`;
297
+ }
298
+ return headers;
299
+ }
263
300
  };
264
301
 
265
302
  // src/managers/session-manager.ts
@@ -267,15 +304,11 @@ var SessionManager = class {
267
304
  /**
268
305
  * Fetch all sessions for an entity
269
306
  */
270
- async fetchSessions(endpoint, entityType, entityId, dbId, authToken) {
307
+ async fetchSessions(endpoint, entityType, entityId, dbId, headers) {
271
308
  const url = new URL(`${endpoint}/sessions`);
272
309
  url.searchParams.set("type", entityType);
273
310
  url.searchParams.set("component_id", entityId);
274
311
  url.searchParams.set("db_id", dbId);
275
- const headers = {};
276
- if (authToken) {
277
- headers["Authorization"] = `Bearer ${authToken}`;
278
- }
279
312
  const response = await fetch(url.toString(), { headers });
280
313
  if (!response.ok) {
281
314
  if (response.status === 404) {
@@ -290,16 +323,12 @@ var SessionManager = class {
290
323
  * Fetch a specific session's runs
291
324
  * Returns an array of RunSchema directly (not wrapped in { data, meta })
292
325
  */
293
- async fetchSession(endpoint, entityType, sessionId, dbId, authToken) {
326
+ async fetchSession(endpoint, entityType, sessionId, dbId, headers) {
294
327
  const url = new URL(`${endpoint}/sessions/${sessionId}/runs`);
295
328
  url.searchParams.set("type", entityType);
296
329
  if (dbId) {
297
330
  url.searchParams.set("db_id", dbId);
298
331
  }
299
- const headers = {};
300
- if (authToken) {
301
- headers["Authorization"] = `Bearer ${authToken}`;
302
- }
303
332
  const response = await fetch(url.toString(), { headers });
304
333
  if (!response.ok) {
305
334
  throw new Error(`Failed to fetch session: ${response.statusText}`);
@@ -309,15 +338,11 @@ var SessionManager = class {
309
338
  /**
310
339
  * Delete a session
311
340
  */
312
- async deleteSession(endpoint, sessionId, dbId, authToken) {
341
+ async deleteSession(endpoint, sessionId, dbId, headers) {
313
342
  const url = new URL(`${endpoint}/sessions/${sessionId}`);
314
343
  if (dbId) {
315
344
  url.searchParams.set("db_id", dbId);
316
345
  }
317
- const headers = {};
318
- if (authToken) {
319
- headers["Authorization"] = `Bearer ${authToken}`;
320
- }
321
346
  const response = await fetch(url.toString(), {
322
347
  method: "DELETE",
323
348
  headers
@@ -928,11 +953,7 @@ var AgnoClient = class extends import_eventemitter3.default {
928
953
  if (userId) {
929
954
  formData.append("user_id", userId);
930
955
  }
931
- const headers = { ...options?.headers };
932
- const authToken = this.configManager.getAuthToken();
933
- if (authToken) {
934
- headers["Authorization"] = `Bearer ${authToken}`;
935
- }
956
+ const headers = this.configManager.buildRequestHeaders(options?.headers);
936
957
  await streamResponse({
937
958
  apiUrl: runUrl,
938
959
  headers,
@@ -1047,12 +1068,13 @@ var AgnoClient = class extends import_eventemitter3.default {
1047
1068
  const entityType = this.configManager.getMode();
1048
1069
  const dbId = this.configManager.getDbId() || "";
1049
1070
  Logger.debug("[AgnoClient] Loading session with:", { entityType, dbId });
1071
+ const headers = this.configManager.buildRequestHeaders();
1050
1072
  const response = await this.sessionManager.fetchSession(
1051
1073
  config.endpoint,
1052
1074
  entityType,
1053
1075
  sessionId,
1054
1076
  dbId,
1055
- config.authToken
1077
+ headers
1056
1078
  );
1057
1079
  const messages = this.sessionManager.convertSessionToMessages(response);
1058
1080
  Logger.debug("[AgnoClient] Setting messages to store:", `${messages.length} messages`);
@@ -1076,12 +1098,13 @@ var AgnoClient = class extends import_eventemitter3.default {
1076
1098
  if (!entityId) {
1077
1099
  throw new Error("Entity ID must be configured");
1078
1100
  }
1101
+ const headers = this.configManager.buildRequestHeaders();
1079
1102
  const sessions = await this.sessionManager.fetchSessions(
1080
1103
  config.endpoint,
1081
1104
  entityType,
1082
1105
  entityId,
1083
1106
  dbId,
1084
- config.authToken
1107
+ headers
1085
1108
  );
1086
1109
  this.state.sessions = sessions;
1087
1110
  this.emit("state:change", this.getState());
@@ -1093,11 +1116,12 @@ var AgnoClient = class extends import_eventemitter3.default {
1093
1116
  async deleteSession(sessionId) {
1094
1117
  const config = this.configManager.getConfig();
1095
1118
  const dbId = this.configManager.getDbId() || "";
1119
+ const headers = this.configManager.buildRequestHeaders();
1096
1120
  await this.sessionManager.deleteSession(
1097
1121
  config.endpoint,
1098
1122
  sessionId,
1099
1123
  dbId,
1100
- config.authToken
1124
+ headers
1101
1125
  );
1102
1126
  this.state.sessions = this.state.sessions.filter(
1103
1127
  (s) => s.session_id !== sessionId
@@ -1248,11 +1272,7 @@ var AgnoClient = class extends import_eventemitter3.default {
1248
1272
  if (userId) {
1249
1273
  formData.append("user_id", userId);
1250
1274
  }
1251
- const headers = { ...options?.headers };
1252
- const authToken = this.configManager.getAuthToken();
1253
- if (authToken) {
1254
- headers["Authorization"] = `Bearer ${authToken}`;
1255
- }
1275
+ const headers = this.configManager.buildRequestHeaders(options?.headers);
1256
1276
  try {
1257
1277
  await streamResponse({
1258
1278
  apiUrl: continueUrl,
@@ -1285,7 +1305,8 @@ var AgnoClient = class extends import_eventemitter3.default {
1285
1305
  */
1286
1306
  async checkStatus() {
1287
1307
  try {
1288
- const response = await fetch(`${this.configManager.getEndpoint()}/health`);
1308
+ const headers = this.configManager.buildRequestHeaders();
1309
+ const response = await fetch(`${this.configManager.getEndpoint()}/health`, { headers });
1289
1310
  const isActive = response.ok;
1290
1311
  this.state.isEndpointActive = isActive;
1291
1312
  this.emit("state:change", this.getState());
@@ -1300,12 +1321,8 @@ var AgnoClient = class extends import_eventemitter3.default {
1300
1321
  * Fetch agents from endpoint
1301
1322
  */
1302
1323
  async fetchAgents() {
1303
- const config = this.configManager.getConfig();
1304
- const headers = {};
1305
- if (config.authToken) {
1306
- headers["Authorization"] = `Bearer ${config.authToken}`;
1307
- }
1308
- const response = await fetch(`${config.endpoint}/agents`, { headers });
1324
+ const headers = this.configManager.buildRequestHeaders();
1325
+ const response = await fetch(`${this.configManager.getEndpoint()}/agents`, { headers });
1309
1326
  if (!response.ok) {
1310
1327
  throw new Error("Failed to fetch agents");
1311
1328
  }
@@ -1318,12 +1335,8 @@ var AgnoClient = class extends import_eventemitter3.default {
1318
1335
  * Fetch teams from endpoint
1319
1336
  */
1320
1337
  async fetchTeams() {
1321
- const config = this.configManager.getConfig();
1322
- const headers = {};
1323
- if (config.authToken) {
1324
- headers["Authorization"] = `Bearer ${config.authToken}`;
1325
- }
1326
- const response = await fetch(`${config.endpoint}/teams`, { headers });
1338
+ const headers = this.configManager.buildRequestHeaders();
1339
+ const response = await fetch(`${this.configManager.getEndpoint()}/teams`, { headers });
1327
1340
  if (!response.ok) {
1328
1341
  throw new Error("Failed to fetch teams");
1329
1342
  }
package/dist/index.mjs CHANGED
@@ -200,6 +200,18 @@ var ConfigManager = class {
200
200
  setUserId(userId) {
201
201
  this.updateField("userId", userId);
202
202
  }
203
+ /**
204
+ * Get custom headers
205
+ */
206
+ getHeaders() {
207
+ return this.config.headers;
208
+ }
209
+ /**
210
+ * Set custom headers
211
+ */
212
+ setHeaders(headers) {
213
+ this.updateField("headers", headers);
214
+ }
203
215
  /**
204
216
  * Get current entity ID (agent or team based on mode)
205
217
  */
@@ -222,6 +234,31 @@ var ConfigManager = class {
222
234
  return `${endpoint}/agents/${encodedEntityId}/runs`;
223
235
  }
224
236
  }
237
+ /**
238
+ * Build request headers by merging global headers, per-request headers, and auth token.
239
+ * Merge order (lowest to highest precedence):
240
+ * 1. Global headers from config
241
+ * 2. Per-request headers (overrides global)
242
+ * 3. Authorization header from authToken (overrides all)
243
+ *
244
+ * @param perRequestHeaders - Optional headers for this specific request
245
+ * @returns Merged headers object ready for fetch
246
+ */
247
+ buildRequestHeaders(perRequestHeaders) {
248
+ const headers = {};
249
+ const globalHeaders = this.getHeaders();
250
+ if (globalHeaders) {
251
+ Object.assign(headers, globalHeaders);
252
+ }
253
+ if (perRequestHeaders) {
254
+ Object.assign(headers, perRequestHeaders);
255
+ }
256
+ const authToken = this.getAuthToken();
257
+ if (authToken) {
258
+ headers["Authorization"] = `Bearer ${authToken}`;
259
+ }
260
+ return headers;
261
+ }
225
262
  };
226
263
 
227
264
  // src/managers/session-manager.ts
@@ -229,15 +266,11 @@ var SessionManager = class {
229
266
  /**
230
267
  * Fetch all sessions for an entity
231
268
  */
232
- async fetchSessions(endpoint, entityType, entityId, dbId, authToken) {
269
+ async fetchSessions(endpoint, entityType, entityId, dbId, headers) {
233
270
  const url = new URL(`${endpoint}/sessions`);
234
271
  url.searchParams.set("type", entityType);
235
272
  url.searchParams.set("component_id", entityId);
236
273
  url.searchParams.set("db_id", dbId);
237
- const headers = {};
238
- if (authToken) {
239
- headers["Authorization"] = `Bearer ${authToken}`;
240
- }
241
274
  const response = await fetch(url.toString(), { headers });
242
275
  if (!response.ok) {
243
276
  if (response.status === 404) {
@@ -252,16 +285,12 @@ var SessionManager = class {
252
285
  * Fetch a specific session's runs
253
286
  * Returns an array of RunSchema directly (not wrapped in { data, meta })
254
287
  */
255
- async fetchSession(endpoint, entityType, sessionId, dbId, authToken) {
288
+ async fetchSession(endpoint, entityType, sessionId, dbId, headers) {
256
289
  const url = new URL(`${endpoint}/sessions/${sessionId}/runs`);
257
290
  url.searchParams.set("type", entityType);
258
291
  if (dbId) {
259
292
  url.searchParams.set("db_id", dbId);
260
293
  }
261
- const headers = {};
262
- if (authToken) {
263
- headers["Authorization"] = `Bearer ${authToken}`;
264
- }
265
294
  const response = await fetch(url.toString(), { headers });
266
295
  if (!response.ok) {
267
296
  throw new Error(`Failed to fetch session: ${response.statusText}`);
@@ -271,15 +300,11 @@ var SessionManager = class {
271
300
  /**
272
301
  * Delete a session
273
302
  */
274
- async deleteSession(endpoint, sessionId, dbId, authToken) {
303
+ async deleteSession(endpoint, sessionId, dbId, headers) {
275
304
  const url = new URL(`${endpoint}/sessions/${sessionId}`);
276
305
  if (dbId) {
277
306
  url.searchParams.set("db_id", dbId);
278
307
  }
279
- const headers = {};
280
- if (authToken) {
281
- headers["Authorization"] = `Bearer ${authToken}`;
282
- }
283
308
  const response = await fetch(url.toString(), {
284
309
  method: "DELETE",
285
310
  headers
@@ -890,11 +915,7 @@ var AgnoClient = class extends EventEmitter {
890
915
  if (userId) {
891
916
  formData.append("user_id", userId);
892
917
  }
893
- const headers = { ...options?.headers };
894
- const authToken = this.configManager.getAuthToken();
895
- if (authToken) {
896
- headers["Authorization"] = `Bearer ${authToken}`;
897
- }
918
+ const headers = this.configManager.buildRequestHeaders(options?.headers);
898
919
  await streamResponse({
899
920
  apiUrl: runUrl,
900
921
  headers,
@@ -1009,12 +1030,13 @@ var AgnoClient = class extends EventEmitter {
1009
1030
  const entityType = this.configManager.getMode();
1010
1031
  const dbId = this.configManager.getDbId() || "";
1011
1032
  Logger.debug("[AgnoClient] Loading session with:", { entityType, dbId });
1033
+ const headers = this.configManager.buildRequestHeaders();
1012
1034
  const response = await this.sessionManager.fetchSession(
1013
1035
  config.endpoint,
1014
1036
  entityType,
1015
1037
  sessionId,
1016
1038
  dbId,
1017
- config.authToken
1039
+ headers
1018
1040
  );
1019
1041
  const messages = this.sessionManager.convertSessionToMessages(response);
1020
1042
  Logger.debug("[AgnoClient] Setting messages to store:", `${messages.length} messages`);
@@ -1038,12 +1060,13 @@ var AgnoClient = class extends EventEmitter {
1038
1060
  if (!entityId) {
1039
1061
  throw new Error("Entity ID must be configured");
1040
1062
  }
1063
+ const headers = this.configManager.buildRequestHeaders();
1041
1064
  const sessions = await this.sessionManager.fetchSessions(
1042
1065
  config.endpoint,
1043
1066
  entityType,
1044
1067
  entityId,
1045
1068
  dbId,
1046
- config.authToken
1069
+ headers
1047
1070
  );
1048
1071
  this.state.sessions = sessions;
1049
1072
  this.emit("state:change", this.getState());
@@ -1055,11 +1078,12 @@ var AgnoClient = class extends EventEmitter {
1055
1078
  async deleteSession(sessionId) {
1056
1079
  const config = this.configManager.getConfig();
1057
1080
  const dbId = this.configManager.getDbId() || "";
1081
+ const headers = this.configManager.buildRequestHeaders();
1058
1082
  await this.sessionManager.deleteSession(
1059
1083
  config.endpoint,
1060
1084
  sessionId,
1061
1085
  dbId,
1062
- config.authToken
1086
+ headers
1063
1087
  );
1064
1088
  this.state.sessions = this.state.sessions.filter(
1065
1089
  (s) => s.session_id !== sessionId
@@ -1210,11 +1234,7 @@ var AgnoClient = class extends EventEmitter {
1210
1234
  if (userId) {
1211
1235
  formData.append("user_id", userId);
1212
1236
  }
1213
- const headers = { ...options?.headers };
1214
- const authToken = this.configManager.getAuthToken();
1215
- if (authToken) {
1216
- headers["Authorization"] = `Bearer ${authToken}`;
1217
- }
1237
+ const headers = this.configManager.buildRequestHeaders(options?.headers);
1218
1238
  try {
1219
1239
  await streamResponse({
1220
1240
  apiUrl: continueUrl,
@@ -1247,7 +1267,8 @@ var AgnoClient = class extends EventEmitter {
1247
1267
  */
1248
1268
  async checkStatus() {
1249
1269
  try {
1250
- const response = await fetch(`${this.configManager.getEndpoint()}/health`);
1270
+ const headers = this.configManager.buildRequestHeaders();
1271
+ const response = await fetch(`${this.configManager.getEndpoint()}/health`, { headers });
1251
1272
  const isActive = response.ok;
1252
1273
  this.state.isEndpointActive = isActive;
1253
1274
  this.emit("state:change", this.getState());
@@ -1262,12 +1283,8 @@ var AgnoClient = class extends EventEmitter {
1262
1283
  * Fetch agents from endpoint
1263
1284
  */
1264
1285
  async fetchAgents() {
1265
- const config = this.configManager.getConfig();
1266
- const headers = {};
1267
- if (config.authToken) {
1268
- headers["Authorization"] = `Bearer ${config.authToken}`;
1269
- }
1270
- const response = await fetch(`${config.endpoint}/agents`, { headers });
1286
+ const headers = this.configManager.buildRequestHeaders();
1287
+ const response = await fetch(`${this.configManager.getEndpoint()}/agents`, { headers });
1271
1288
  if (!response.ok) {
1272
1289
  throw new Error("Failed to fetch agents");
1273
1290
  }
@@ -1280,12 +1297,8 @@ var AgnoClient = class extends EventEmitter {
1280
1297
  * Fetch teams from endpoint
1281
1298
  */
1282
1299
  async fetchTeams() {
1283
- const config = this.configManager.getConfig();
1284
- const headers = {};
1285
- if (config.authToken) {
1286
- headers["Authorization"] = `Bearer ${config.authToken}`;
1287
- }
1288
- const response = await fetch(`${config.endpoint}/teams`, { headers });
1300
+ const headers = this.configManager.buildRequestHeaders();
1301
+ const response = await fetch(`${this.configManager.getEndpoint()}/teams`, { headers });
1289
1302
  if (!response.ok) {
1290
1303
  throw new Error("Failed to fetch teams");
1291
1304
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antipopp/agno-client",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Core client library for Agno agents with streaming support and HITL frontend tool execution",
5
5
  "author": "antipopp",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "eventemitter3": "^5.0.1",
37
- "@antipopp/agno-types": "0.6.1"
37
+ "@antipopp/agno-types": "0.7.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "tsup": "^8.0.1",