@ideascol/agents-generator-sdk 0.0.3-rc5 → 0.0.4-rc1

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/bin/cli.js CHANGED
@@ -598,7 +598,7 @@ var OpenAPI;
598
598
  var init_OpenAPI = __esm(() => {
599
599
  OpenAPI = {
600
600
  BASE: "",
601
- VERSION: "main-3e9b5b5b62a0af3d34e07f2a82593d3a5b0543da",
601
+ VERSION: "main-6851016f7efc01be9f722f975c072d2cd49e46e7",
602
602
  WITH_CREDENTIALS: false,
603
603
  CREDENTIALS: "include",
604
604
  TOKEN: undefined,
@@ -1135,11 +1135,229 @@ var init_agentsCommand = __esm(() => {
1135
1135
  agentsCommand_default = commandAgents;
1136
1136
  });
1137
1137
 
1138
+ // src/lib/index.ts
1139
+ class AgentClient {
1140
+ agent;
1141
+ conversations;
1142
+ mcpServers;
1143
+ root;
1144
+ ApiError;
1145
+ CancelError;
1146
+ CancelablePromise;
1147
+ OpenAPI;
1148
+ conversationsStream;
1149
+ constructor({
1150
+ apiUrl,
1151
+ apiToken
1152
+ }) {
1153
+ OpenAPI.BASE = apiUrl;
1154
+ OpenAPI.TOKEN = apiToken;
1155
+ OpenAPI.HEADERS = {
1156
+ "Api-Version": OpenAPI.VERSION
1157
+ };
1158
+ this.agent = AgentService;
1159
+ this.conversations = ConversationsService;
1160
+ this.mcpServers = McpServersService;
1161
+ this.root = RootService;
1162
+ this.conversationsStream = ConversationsServiceStream;
1163
+ this.ApiError = ApiError;
1164
+ this.CancelError = CancelError;
1165
+ this.CancelablePromise = CancelablePromise;
1166
+ this.OpenAPI = OpenAPI;
1167
+ }
1168
+ sendMessageWithStreaming(conversationId, requestBody, callbacks) {
1169
+ return ConversationsServiceStream.addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, callbacks);
1170
+ }
1171
+ sendMessage(conversationId, requestBody) {
1172
+ return ConversationsServiceStream.addMessageConversationsConversationIdMessagesPost(conversationId, requestBody);
1173
+ }
1174
+ }
1175
+ var ConversationsServiceStream;
1176
+ var init_lib = __esm(() => {
1177
+ init_agents_generator();
1178
+ ConversationsServiceStream = class ConversationsServiceStream extends ConversationsService {
1179
+ constructor() {
1180
+ super();
1181
+ }
1182
+ static addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, callbacks) {
1183
+ const apiUrl = OpenAPI.BASE;
1184
+ const url = `${apiUrl}/conversations/${conversationId}/messages`;
1185
+ const controller = new AbortController;
1186
+ const headers = new Headers({
1187
+ "Content-Type": "application/json",
1188
+ Accept: "text/event-stream"
1189
+ });
1190
+ if (OpenAPI.TOKEN) {
1191
+ if (typeof OpenAPI.TOKEN === "function") {
1192
+ OpenAPI.TOKEN({ url, method: "POST", body: requestBody }).then((token) => {
1193
+ headers.append("Authorization", `Bearer ${token}`);
1194
+ }).catch((error) => {
1195
+ if (callbacks.onError) {
1196
+ callbacks.onError(new Error(`Failed to get auth token: ${error.message}`));
1197
+ }
1198
+ });
1199
+ } else {
1200
+ headers.append("Authorization", `Bearer ${OpenAPI.TOKEN}`);
1201
+ }
1202
+ }
1203
+ fetch(url, {
1204
+ method: "POST",
1205
+ headers,
1206
+ body: JSON.stringify(requestBody),
1207
+ credentials: OpenAPI.WITH_CREDENTIALS ? OpenAPI.CREDENTIALS : undefined,
1208
+ signal: controller.signal
1209
+ }).then((response) => {
1210
+ if (!response.ok) {
1211
+ throw new Error(`Error: ${response.status} - ${response.statusText}`);
1212
+ }
1213
+ if (!response.body) {
1214
+ throw new Error("ReadableStream not supported");
1215
+ }
1216
+ const reader = response.body.getReader();
1217
+ const decoder = new TextDecoder;
1218
+ let buffer = "";
1219
+ let fullMessage = "";
1220
+ let isDirectTextMode = false;
1221
+ function processStream() {
1222
+ reader.read().then(({ done, value }) => {
1223
+ if (done) {
1224
+ console.log("Stream completado");
1225
+ if (buffer.length > 0) {
1226
+ console.log("Procesando buffer final:", buffer);
1227
+ if (isDirectTextMode) {
1228
+ fullMessage += buffer;
1229
+ if (callbacks.onMessage) {
1230
+ console.log("Actualizando mensaje final (texto directo):", fullMessage);
1231
+ callbacks.onMessage(fullMessage);
1232
+ }
1233
+ } else {
1234
+ let eventEnd2 = buffer.indexOf(`
1235
+
1236
+ `);
1237
+ if (eventEnd2 > -1) {
1238
+ const eventData = buffer.substring(0, eventEnd2);
1239
+ buffer = buffer.substring(eventEnd2 + 2);
1240
+ if (eventData.startsWith("data: ")) {
1241
+ try {
1242
+ const jsonStr = eventData.substring(6);
1243
+ const data = JSON.parse(jsonStr);
1244
+ if (data.type === "message" && data.content && callbacks.onMessage) {
1245
+ fullMessage = data.content;
1246
+ callbacks.onMessage(fullMessage);
1247
+ } else if (data.type === "done" && data.message_id && callbacks.onDone) {
1248
+ callbacks.onDone(data.message_id);
1249
+ }
1250
+ } catch (e) {
1251
+ fullMessage += eventData.substring(6);
1252
+ if (callbacks.onMessage) {
1253
+ callbacks.onMessage(fullMessage);
1254
+ }
1255
+ }
1256
+ }
1257
+ }
1258
+ if (buffer.length > 0) {
1259
+ fullMessage += buffer;
1260
+ if (callbacks.onMessage) {
1261
+ console.log("Actualizando mensaje final (buffer restante):", fullMessage);
1262
+ callbacks.onMessage(fullMessage);
1263
+ }
1264
+ }
1265
+ }
1266
+ }
1267
+ if (callbacks.onDone) {
1268
+ callbacks.onDone("stream-completed");
1269
+ }
1270
+ return;
1271
+ }
1272
+ const chunk = decoder.decode(value, { stream: true });
1273
+ buffer += chunk;
1274
+ console.log("Chunk recibido:", chunk);
1275
+ let eventEnd = buffer.indexOf(`
1276
+
1277
+ `);
1278
+ if (buffer.length > 50 && eventEnd === -1 && !isDirectTextMode) {
1279
+ isDirectTextMode = true;
1280
+ console.log("Detectado modo texto directo");
1281
+ }
1282
+ if (isDirectTextMode) {
1283
+ fullMessage += chunk;
1284
+ if (callbacks.onMessage) {
1285
+ console.log("Actualizando con texto directo:", fullMessage);
1286
+ callbacks.onMessage(fullMessage);
1287
+ }
1288
+ } else {
1289
+ while (eventEnd > -1) {
1290
+ const eventData = buffer.substring(0, eventEnd);
1291
+ buffer = buffer.substring(eventEnd + 2);
1292
+ if (eventData.startsWith("data: ")) {
1293
+ const jsonStr = eventData.substring(6);
1294
+ try {
1295
+ const data = JSON.parse(jsonStr);
1296
+ console.log("Evento SSE recibido:", data);
1297
+ if (data.type === "message" && data.content && callbacks.onMessage) {
1298
+ fullMessage = data.content;
1299
+ callbacks.onMessage(fullMessage);
1300
+ } else if (data.type === "done" && data.message_id && callbacks.onDone) {
1301
+ callbacks.onDone(data.message_id);
1302
+ }
1303
+ } catch (e) {
1304
+ console.error("Error al parsear JSON del evento:", e);
1305
+ if (eventData.startsWith("data: ")) {
1306
+ const directContent = eventData.substring(6);
1307
+ fullMessage += directContent;
1308
+ if (callbacks.onMessage) {
1309
+ console.log("Actualizando con texto SSE simple:", fullMessage);
1310
+ callbacks.onMessage(fullMessage);
1311
+ }
1312
+ } else {
1313
+ if (callbacks.onError) {
1314
+ callbacks.onError(new Error(`Error parsing SSE event: ${e}`));
1315
+ }
1316
+ }
1317
+ }
1318
+ } else {
1319
+ fullMessage += eventData;
1320
+ if (callbacks.onMessage) {
1321
+ console.log("Actualizando con evento no reconocido:", fullMessage);
1322
+ callbacks.onMessage(fullMessage);
1323
+ }
1324
+ }
1325
+ eventEnd = buffer.indexOf(`
1326
+
1327
+ `);
1328
+ }
1329
+ if (buffer.length > 20 && !buffer.includes("data: ")) {
1330
+ fullMessage += buffer;
1331
+ buffer = "";
1332
+ if (callbacks.onMessage) {
1333
+ console.log("Actualizando con buffer residual:", fullMessage);
1334
+ callbacks.onMessage(fullMessage);
1335
+ }
1336
+ }
1337
+ }
1338
+ processStream();
1339
+ }).catch((error) => {
1340
+ if (callbacks.onError) {
1341
+ callbacks.onError(error);
1342
+ }
1343
+ });
1344
+ }
1345
+ processStream();
1346
+ }).catch((error) => {
1347
+ if (callbacks.onError) {
1348
+ callbacks.onError(error);
1349
+ }
1350
+ });
1351
+ return () => controller.abort();
1352
+ }
1353
+ };
1354
+ });
1355
+
1138
1356
  // src/commands/rootCommand.ts
1139
1357
  var import_cli_maker2, rootCommand, rootCommand_default;
1140
1358
  var init_rootCommand = __esm(() => {
1141
1359
  import_cli_maker2 = __toESM(require_dist());
1142
- init_agents_generator();
1360
+ init_lib();
1143
1361
  rootCommand = {
1144
1362
  name: "version",
1145
1363
  description: "Get the version of the API",
@@ -1148,34 +1366,82 @@ var init_rootCommand = __esm(() => {
1148
1366
  description: "The URL of the API",
1149
1367
  required: false,
1150
1368
  type: import_cli_maker2.ParamType.Url
1369
+ }, {
1370
+ name: "apiToken",
1371
+ description: "The API token",
1372
+ required: false,
1373
+ type: import_cli_maker2.ParamType.Text
1151
1374
  }],
1152
1375
  action: async (args) => {
1153
- OpenAPI["BASE"] = args.URL || "https://api.agentsgenerator.dev/";
1154
- console.log(OpenAPI);
1155
- const hello = await RootService.healthCheckHealthGet();
1376
+ const client = new AgentClient({
1377
+ apiUrl: args.URL || "https://api.agentsgenerator.dev/",
1378
+ apiToken: args.apiToken
1379
+ });
1380
+ const hello = await client.root.healthCheckHealthGet();
1156
1381
  console.log(hello);
1157
1382
  }
1158
1383
  };
1159
1384
  rootCommand_default = rootCommand;
1160
1385
  });
1161
1386
 
1387
+ // src/commands/conversationsCommand.ts
1388
+ var import_cli_maker3, commandConversations, conversationsCommand_default;
1389
+ var init_conversationsCommand = __esm(() => {
1390
+ import_cli_maker3 = __toESM(require_dist());
1391
+ init_agents_generator();
1392
+ commandConversations = {
1393
+ name: "getConversations",
1394
+ description: "Get the list of conversations",
1395
+ params: [{
1396
+ name: "URL",
1397
+ description: "The URL of the API",
1398
+ required: true,
1399
+ type: import_cli_maker3.ParamType.Url
1400
+ }, {
1401
+ name: "conversationId",
1402
+ description: "The ID of the conversation",
1403
+ required: true,
1404
+ type: import_cli_maker3.ParamType.Text
1405
+ }, {
1406
+ name: "agentId",
1407
+ description: "The ID of the agent",
1408
+ required: true,
1409
+ type: import_cli_maker3.ParamType.Text
1410
+ }],
1411
+ action: async (args) => {
1412
+ OpenAPI["BASE"] = args.URL;
1413
+ const conversationId = args.conversationId;
1414
+ const agentId = args.agentId;
1415
+ const conversationList = await ConversationsService.getAgentConversationsConversationsAgentAgentIdGet(agentId);
1416
+ const conversations = await ConversationsService.getConversationConversationsConversationIdGet(conversationId);
1417
+ return {
1418
+ conversationList,
1419
+ conversations
1420
+ };
1421
+ }
1422
+ };
1423
+ conversationsCommand_default = commandConversations;
1424
+ });
1425
+
1162
1426
  // src/cli.ts
1163
1427
  var exports_cli = {};
1164
1428
  __export(exports_cli, {
1165
1429
  cli: () => cli
1166
1430
  });
1167
- var import_cli_maker3, cli;
1431
+ var import_cli_maker4, cli;
1168
1432
  var init_cli = __esm(() => {
1169
- import_cli_maker3 = __toESM(require_dist());
1433
+ import_cli_maker4 = __toESM(require_dist());
1170
1434
  init_agents_generator();
1171
1435
  init_agentsCommand();
1172
1436
  init_rootCommand();
1173
- cli = new import_cli_maker3.CLI("@ideascol/agents-generator-sdk", "agents-generator-sdk", {
1437
+ init_conversationsCommand();
1438
+ cli = new import_cli_maker4.CLI("@ideascol/agents-generator-sdk", "agents-generator-sdk", {
1174
1439
  interactive: true,
1175
1440
  version: OpenAPI.VERSION
1176
1441
  });
1177
1442
  cli.command(rootCommand_default);
1178
1443
  cli.command(agentsCommand_default);
1444
+ cli.command(conversationsCommand_default);
1179
1445
  cli.parse(process.argv);
1180
1446
  });
1181
1447
 
@@ -0,0 +1,3 @@
1
+ import { Command } from '@ideascol/cli-maker';
2
+ declare let commandConversations: Command;
3
+ export default commandConversations;
package/dist/index.js CHANGED
@@ -166,7 +166,7 @@ var OpenAPI;
166
166
  var init_OpenAPI = __esm(() => {
167
167
  OpenAPI = {
168
168
  BASE: "",
169
- VERSION: "main-3e9b5b5b62a0af3d34e07f2a82593d3a5b0543da",
169
+ VERSION: "main-6851016f7efc01be9f722f975c072d2cd49e46e7",
170
170
  WITH_CREDENTIALS: false,
171
171
  CREDENTIALS: "include",
172
172
  TOKEN: undefined,
@@ -679,198 +679,228 @@ var init_agents_generator = __esm(() => {
679
679
  init_RootService();
680
680
  });
681
681
 
682
- // src/index.ts
683
- var exports_src = {};
684
- __export(exports_src, {
685
- RootService: () => RootService,
686
- OpenAPI: () => OpenAPI,
687
- McpServersService: () => McpServersService,
688
- ConversationsServiceStream: () => ConversationsServiceStream,
689
- ConversationsService: () => ConversationsService,
690
- CancelablePromise: () => CancelablePromise,
691
- CancelError: () => CancelError,
692
- ApiError: () => ApiError,
693
- AgentService: () => AgentService
694
- });
695
- module.exports = __toCommonJS(exports_src);
696
-
697
682
  // src/lib/index.ts
698
- init_agents_generator();
699
- init_agents_generator();
700
-
701
- class ConversationsServiceStream extends ConversationsService {
702
- constructor() {
703
- super();
704
- }
705
- static addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, callbacks) {
706
- const apiUrl = OpenAPI.BASE;
707
- const url = `${apiUrl}/conversations/${conversationId}/messages`;
708
- const controller = new AbortController;
709
- const headers = new Headers({
710
- "Content-Type": "application/json",
711
- Accept: "text/event-stream"
712
- });
713
- if (OpenAPI.TOKEN) {
714
- if (typeof OpenAPI.TOKEN === "function") {
715
- OpenAPI.TOKEN({ url, method: "POST", body: requestBody }).then((token) => {
716
- headers.append("Authorization", `Bearer ${token}`);
717
- }).catch((error) => {
718
- if (callbacks.onError) {
719
- callbacks.onError(new Error(`Failed to get auth token: ${error.message}`));
720
- }
721
- });
722
- } else {
723
- headers.append("Authorization", `Bearer ${OpenAPI.TOKEN}`);
724
- }
683
+ class AgentClient {
684
+ agent;
685
+ conversations;
686
+ mcpServers;
687
+ root;
688
+ ApiError;
689
+ CancelError;
690
+ CancelablePromise;
691
+ OpenAPI;
692
+ conversationsStream;
693
+ constructor({
694
+ apiUrl,
695
+ apiToken
696
+ }) {
697
+ OpenAPI.BASE = apiUrl;
698
+ OpenAPI.TOKEN = apiToken;
699
+ OpenAPI.HEADERS = {
700
+ "Api-Version": OpenAPI.VERSION
701
+ };
702
+ this.agent = AgentService;
703
+ this.conversations = ConversationsService;
704
+ this.mcpServers = McpServersService;
705
+ this.root = RootService;
706
+ this.conversationsStream = ConversationsServiceStream;
707
+ this.ApiError = ApiError;
708
+ this.CancelError = CancelError;
709
+ this.CancelablePromise = CancelablePromise;
710
+ this.OpenAPI = OpenAPI;
711
+ }
712
+ sendMessageWithStreaming(conversationId, requestBody, callbacks) {
713
+ return ConversationsServiceStream.addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, callbacks);
714
+ }
715
+ sendMessage(conversationId, requestBody) {
716
+ return ConversationsServiceStream.addMessageConversationsConversationIdMessagesPost(conversationId, requestBody);
717
+ }
718
+ }
719
+ var ConversationsServiceStream;
720
+ var init_lib = __esm(() => {
721
+ init_agents_generator();
722
+ ConversationsServiceStream = class ConversationsServiceStream extends ConversationsService {
723
+ constructor() {
724
+ super();
725
725
  }
726
- fetch(url, {
727
- method: "POST",
728
- headers,
729
- body: JSON.stringify(requestBody),
730
- credentials: OpenAPI.WITH_CREDENTIALS ? OpenAPI.CREDENTIALS : undefined,
731
- signal: controller.signal
732
- }).then((response) => {
733
- if (!response.ok) {
734
- throw new Error(`Error: ${response.status} - ${response.statusText}`);
735
- }
736
- if (!response.body) {
737
- throw new Error("ReadableStream not supported");
726
+ static addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, callbacks) {
727
+ const apiUrl = OpenAPI.BASE;
728
+ const url = `${apiUrl}/conversations/${conversationId}/messages`;
729
+ const controller = new AbortController;
730
+ const headers = new Headers({
731
+ "Content-Type": "application/json",
732
+ Accept: "text/event-stream"
733
+ });
734
+ if (OpenAPI.TOKEN) {
735
+ if (typeof OpenAPI.TOKEN === "function") {
736
+ OpenAPI.TOKEN({ url, method: "POST", body: requestBody }).then((token) => {
737
+ headers.append("Authorization", `Bearer ${token}`);
738
+ }).catch((error) => {
739
+ if (callbacks.onError) {
740
+ callbacks.onError(new Error(`Failed to get auth token: ${error.message}`));
741
+ }
742
+ });
743
+ } else {
744
+ headers.append("Authorization", `Bearer ${OpenAPI.TOKEN}`);
745
+ }
738
746
  }
739
- const reader = response.body.getReader();
740
- const decoder = new TextDecoder;
741
- let buffer = "";
742
- let fullMessage = "";
743
- let isDirectTextMode = false;
744
- function processStream() {
745
- reader.read().then(({ done, value }) => {
746
- if (done) {
747
- console.log("Stream completado");
748
- if (buffer.length > 0) {
749
- console.log("Procesando buffer final:", buffer);
750
- if (isDirectTextMode) {
751
- fullMessage += buffer;
752
- if (callbacks.onMessage) {
753
- console.log("Actualizando mensaje final (texto directo):", fullMessage);
754
- callbacks.onMessage(fullMessage);
755
- }
756
- } else {
757
- let eventEnd2 = buffer.indexOf(`
747
+ fetch(url, {
748
+ method: "POST",
749
+ headers,
750
+ body: JSON.stringify(requestBody),
751
+ credentials: OpenAPI.WITH_CREDENTIALS ? OpenAPI.CREDENTIALS : undefined,
752
+ signal: controller.signal
753
+ }).then((response) => {
754
+ if (!response.ok) {
755
+ throw new Error(`Error: ${response.status} - ${response.statusText}`);
756
+ }
757
+ if (!response.body) {
758
+ throw new Error("ReadableStream not supported");
759
+ }
760
+ const reader = response.body.getReader();
761
+ const decoder = new TextDecoder;
762
+ let buffer = "";
763
+ let fullMessage = "";
764
+ let isDirectTextMode = false;
765
+ function processStream() {
766
+ reader.read().then(({ done, value }) => {
767
+ if (done) {
768
+ console.log("Stream completado");
769
+ if (buffer.length > 0) {
770
+ console.log("Procesando buffer final:", buffer);
771
+ if (isDirectTextMode) {
772
+ fullMessage += buffer;
773
+ if (callbacks.onMessage) {
774
+ console.log("Actualizando mensaje final (texto directo):", fullMessage);
775
+ callbacks.onMessage(fullMessage);
776
+ }
777
+ } else {
778
+ let eventEnd2 = buffer.indexOf(`
758
779
 
759
780
  `);
760
- if (eventEnd2 > -1) {
761
- const eventData = buffer.substring(0, eventEnd2);
762
- buffer = buffer.substring(eventEnd2 + 2);
763
- if (eventData.startsWith("data: ")) {
764
- try {
765
- const jsonStr = eventData.substring(6);
766
- const data = JSON.parse(jsonStr);
767
- if (data.type === "message" && data.content && callbacks.onMessage) {
768
- fullMessage = data.content;
769
- callbacks.onMessage(fullMessage);
770
- } else if (data.type === "done" && data.message_id && callbacks.onDone) {
771
- callbacks.onDone(data.message_id);
772
- }
773
- } catch (e) {
774
- fullMessage += eventData.substring(6);
775
- if (callbacks.onMessage) {
776
- callbacks.onMessage(fullMessage);
781
+ if (eventEnd2 > -1) {
782
+ const eventData = buffer.substring(0, eventEnd2);
783
+ buffer = buffer.substring(eventEnd2 + 2);
784
+ if (eventData.startsWith("data: ")) {
785
+ try {
786
+ const jsonStr = eventData.substring(6);
787
+ const data = JSON.parse(jsonStr);
788
+ if (data.type === "message" && data.content && callbacks.onMessage) {
789
+ fullMessage = data.content;
790
+ callbacks.onMessage(fullMessage);
791
+ } else if (data.type === "done" && data.message_id && callbacks.onDone) {
792
+ callbacks.onDone(data.message_id);
793
+ }
794
+ } catch (e) {
795
+ fullMessage += eventData.substring(6);
796
+ if (callbacks.onMessage) {
797
+ callbacks.onMessage(fullMessage);
798
+ }
777
799
  }
778
800
  }
779
801
  }
780
- }
781
- if (buffer.length > 0) {
782
- fullMessage += buffer;
783
- if (callbacks.onMessage) {
784
- console.log("Actualizando mensaje final (buffer restante):", fullMessage);
785
- callbacks.onMessage(fullMessage);
802
+ if (buffer.length > 0) {
803
+ fullMessage += buffer;
804
+ if (callbacks.onMessage) {
805
+ console.log("Actualizando mensaje final (buffer restante):", fullMessage);
806
+ callbacks.onMessage(fullMessage);
807
+ }
786
808
  }
787
809
  }
788
810
  }
811
+ if (callbacks.onDone) {
812
+ callbacks.onDone("stream-completed");
813
+ }
814
+ return;
789
815
  }
790
- if (callbacks.onDone) {
791
- callbacks.onDone("stream-completed");
792
- }
793
- return;
794
- }
795
- const chunk = decoder.decode(value, { stream: true });
796
- buffer += chunk;
797
- console.log("Chunk recibido:", chunk);
798
- let eventEnd = buffer.indexOf(`
816
+ const chunk = decoder.decode(value, { stream: true });
817
+ buffer += chunk;
818
+ console.log("Chunk recibido:", chunk);
819
+ let eventEnd = buffer.indexOf(`
799
820
 
800
821
  `);
801
- if (buffer.length > 50 && eventEnd === -1 && !isDirectTextMode) {
802
- isDirectTextMode = true;
803
- console.log("Detectado modo texto directo");
804
- }
805
- if (isDirectTextMode) {
806
- fullMessage += chunk;
807
- if (callbacks.onMessage) {
808
- console.log("Actualizando con texto directo:", fullMessage);
809
- callbacks.onMessage(fullMessage);
822
+ if (buffer.length > 50 && eventEnd === -1 && !isDirectTextMode) {
823
+ isDirectTextMode = true;
824
+ console.log("Detectado modo texto directo");
810
825
  }
811
- } else {
812
- while (eventEnd > -1) {
813
- const eventData = buffer.substring(0, eventEnd);
814
- buffer = buffer.substring(eventEnd + 2);
815
- if (eventData.startsWith("data: ")) {
816
- const jsonStr = eventData.substring(6);
817
- try {
818
- const data = JSON.parse(jsonStr);
819
- console.log("Evento SSE recibido:", data);
820
- if (data.type === "message" && data.content && callbacks.onMessage) {
821
- fullMessage = data.content;
822
- callbacks.onMessage(fullMessage);
823
- } else if (data.type === "done" && data.message_id && callbacks.onDone) {
824
- callbacks.onDone(data.message_id);
825
- }
826
- } catch (e) {
827
- console.error("Error al parsear JSON del evento:", e);
828
- if (eventData.startsWith("data: ")) {
829
- const directContent = eventData.substring(6);
830
- fullMessage += directContent;
831
- if (callbacks.onMessage) {
832
- console.log("Actualizando con texto SSE simple:", fullMessage);
826
+ if (isDirectTextMode) {
827
+ fullMessage += chunk;
828
+ if (callbacks.onMessage) {
829
+ console.log("Actualizando con texto directo:", fullMessage);
830
+ callbacks.onMessage(fullMessage);
831
+ }
832
+ } else {
833
+ while (eventEnd > -1) {
834
+ const eventData = buffer.substring(0, eventEnd);
835
+ buffer = buffer.substring(eventEnd + 2);
836
+ if (eventData.startsWith("data: ")) {
837
+ const jsonStr = eventData.substring(6);
838
+ try {
839
+ const data = JSON.parse(jsonStr);
840
+ console.log("Evento SSE recibido:", data);
841
+ if (data.type === "message" && data.content && callbacks.onMessage) {
842
+ fullMessage = data.content;
833
843
  callbacks.onMessage(fullMessage);
844
+ } else if (data.type === "done" && data.message_id && callbacks.onDone) {
845
+ callbacks.onDone(data.message_id);
834
846
  }
835
- } else {
836
- if (callbacks.onError) {
837
- callbacks.onError(new Error(`Error parsing SSE event: ${e}`));
847
+ } catch (e) {
848
+ console.error("Error al parsear JSON del evento:", e);
849
+ if (eventData.startsWith("data: ")) {
850
+ const directContent = eventData.substring(6);
851
+ fullMessage += directContent;
852
+ if (callbacks.onMessage) {
853
+ console.log("Actualizando con texto SSE simple:", fullMessage);
854
+ callbacks.onMessage(fullMessage);
855
+ }
856
+ } else {
857
+ if (callbacks.onError) {
858
+ callbacks.onError(new Error(`Error parsing SSE event: ${e}`));
859
+ }
838
860
  }
839
861
  }
862
+ } else {
863
+ fullMessage += eventData;
864
+ if (callbacks.onMessage) {
865
+ console.log("Actualizando con evento no reconocido:", fullMessage);
866
+ callbacks.onMessage(fullMessage);
867
+ }
840
868
  }
841
- } else {
842
- fullMessage += eventData;
869
+ eventEnd = buffer.indexOf(`
870
+
871
+ `);
872
+ }
873
+ if (buffer.length > 20 && !buffer.includes("data: ")) {
874
+ fullMessage += buffer;
875
+ buffer = "";
843
876
  if (callbacks.onMessage) {
844
- console.log("Actualizando con evento no reconocido:", fullMessage);
877
+ console.log("Actualizando con buffer residual:", fullMessage);
845
878
  callbacks.onMessage(fullMessage);
846
879
  }
847
880
  }
848
- eventEnd = buffer.indexOf(`
849
-
850
- `);
851
881
  }
852
- if (buffer.length > 20 && !buffer.includes("data: ")) {
853
- fullMessage += buffer;
854
- buffer = "";
855
- if (callbacks.onMessage) {
856
- console.log("Actualizando con buffer residual:", fullMessage);
857
- callbacks.onMessage(fullMessage);
858
- }
882
+ processStream();
883
+ }).catch((error) => {
884
+ if (callbacks.onError) {
885
+ callbacks.onError(error);
859
886
  }
860
- }
861
- processStream();
862
- }).catch((error) => {
863
- if (callbacks.onError) {
864
- callbacks.onError(error);
865
- }
866
- });
867
- }
868
- processStream();
869
- }).catch((error) => {
870
- if (callbacks.onError) {
871
- callbacks.onError(error);
872
- }
873
- });
874
- return () => controller.abort();
875
- }
876
- }
887
+ });
888
+ }
889
+ processStream();
890
+ }).catch((error) => {
891
+ if (callbacks.onError) {
892
+ callbacks.onError(error);
893
+ }
894
+ });
895
+ return () => controller.abort();
896
+ }
897
+ };
898
+ });
899
+
900
+ // src/index.ts
901
+ var exports_src = {};
902
+ __export(exports_src, {
903
+ AgentClient: () => AgentClient
904
+ });
905
+ module.exports = __toCommonJS(exports_src);
906
+ init_lib();
@@ -10,6 +10,7 @@ export type { ConversationCreate } from './models/ConversationCreate';
10
10
  export type { ConversationResponse } from './models/ConversationResponse';
11
11
  export type { ConversationUpdate } from './models/ConversationUpdate';
12
12
  export type { Edge } from './models/Edge';
13
+ export type { ErrorResponse } from './models/ErrorResponse';
13
14
  export type { Handoff } from './models/Handoff';
14
15
  export type { HTTPValidationError } from './models/HTTPValidationError';
15
16
  export type { MarkerEnd } from './models/MarkerEnd';
@@ -0,0 +1,4 @@
1
+ export type ErrorResponse = {
2
+ status: string;
3
+ message: string;
4
+ };
@@ -46,13 +46,9 @@ export declare class ConversationsService {
46
46
  * Add Message
47
47
  * @param conversationId
48
48
  * @param requestBody
49
- * @param accept Set to 'text/event-stream' to receive streaming events
49
+ * @param accept Content type to receive: 'text/event-stream' for streaming or 'text/plain' for plain text
50
50
  * @returns any Successful response
51
51
  * @throws ApiError
52
52
  */
53
- static addMessageConversationsConversationIdMessagesPost(conversationId: string, requestBody: MessageCreate, accept?: string): CancelablePromise<{
54
- status: string;
55
- message: string;
56
- message_id?: string;
57
- }>;
53
+ static addMessageConversationsConversationIdMessagesPost(conversationId: string, requestBody: MessageCreate, accept?: (string | null)): CancelablePromise<any>;
58
54
  }
@@ -1,5 +1,4 @@
1
- import { ConversationsService, MessageCreate } from "./clients/agents-generator";
2
- export * from "./clients/agents-generator";
1
+ import { ApiError, CancelablePromise, CancelError, ConversationsService, MessageCreate, OpenAPI, AgentService, McpServersService, RootService } from "./clients/agents-generator";
3
2
  export interface StreamEvent {
4
3
  type: string;
5
4
  content?: string;
@@ -10,7 +9,7 @@ export interface StreamCallbacks {
10
9
  onDone?: (messageId: string) => void;
11
10
  onError?: (error: Error) => void;
12
11
  }
13
- export declare class ConversationsServiceStream extends ConversationsService {
12
+ declare class ConversationsServiceStream extends ConversationsService {
14
13
  constructor();
15
14
  /**
16
15
  * Add Message with SSE streaming support
@@ -21,3 +20,31 @@ export declare class ConversationsServiceStream extends ConversationsService {
21
20
  */
22
21
  static addMessageConversationsConversationIdMessagesPostStream(conversationId: string, requestBody: MessageCreate, callbacks: StreamCallbacks): () => void;
23
22
  }
23
+ export declare class AgentClient {
24
+ agent: typeof AgentService;
25
+ conversations: typeof ConversationsService;
26
+ mcpServers: typeof McpServersService;
27
+ root: typeof RootService;
28
+ ApiError: typeof ApiError;
29
+ CancelError: typeof CancelError;
30
+ CancelablePromise: typeof CancelablePromise;
31
+ OpenAPI: typeof OpenAPI;
32
+ conversationsStream: typeof ConversationsServiceStream;
33
+ constructor({ apiUrl, apiToken, }: {
34
+ apiUrl: string;
35
+ apiToken: string;
36
+ });
37
+ /**
38
+ * Envía un mensaje a una conversación con soporte para streaming
39
+ */
40
+ sendMessageWithStreaming(conversationId: string, requestBody: MessageCreate, callbacks: StreamCallbacks): () => void;
41
+ /**
42
+ * Envía un mensaje a una conversación sin streaming
43
+ */
44
+ sendMessage(conversationId: string, requestBody: MessageCreate): CancelablePromise<{
45
+ status: string;
46
+ message: string;
47
+ message_id?: string;
48
+ }>;
49
+ }
50
+ export default AgentClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ideascol/agents-generator-sdk",
3
- "version": "0.0.3-rc5",
3
+ "version": "0.0.4-rc1",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "bun test",