@ideascol/agents-generator-sdk 0.3.3 → 0.3.5

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 CHANGED
@@ -4,6 +4,8 @@ agents-generator-sdk
4
4
 
5
5
  ## Usage as library
6
6
 
7
+ ### Basic Usage - Get Agents
8
+
7
9
  ```ts
8
10
  import { useEffect, useState } from 'react';
9
11
  import {
@@ -39,6 +41,100 @@ export function Agents() {
39
41
  }
40
42
  ```
41
43
 
44
+ ### Send Message with Transfer Detection (Synchronous)
45
+
46
+ The `sendMessage` method now uses streaming internally to detect agent transfers (handoffs). It returns a promise with the complete response including any transfers that occurred.
47
+
48
+ ```ts
49
+ import { AgentClient, SendMessageResponse } from '@ideascol/agents-generator-sdk';
50
+
51
+ const client = new AgentClient({
52
+ apiUrl: 'https://api.agentsgenerator.dev',
53
+ apiToken: 'YOUR_API_TOKEN',
54
+ });
55
+
56
+ // Send a message and get the complete response with transfers
57
+ const response: SendMessageResponse = await client.sendMessage(
58
+ 'conversation-id',
59
+ { content: 'Hello, I need help with billing' }
60
+ );
61
+
62
+ console.log('Message:', response.message);
63
+ console.log('Message ID:', response.message_id);
64
+
65
+ // Check if there were any transfers
66
+ if (response.transfers && response.transfers.length > 0) {
67
+ console.log('Transfers detected:');
68
+ response.transfers.forEach(transfer => {
69
+ console.log(` From: ${transfer.from_agent}`);
70
+ console.log(` To: ${transfer.to_agent}`);
71
+ console.log(` Reason: ${transfer.reason}`);
72
+ });
73
+ }
74
+ ```
75
+
76
+ ### Send Message with Streaming (Real-time updates)
77
+
78
+ For real-time updates and custom handling of events, use `sendMessageWithStreaming`:
79
+
80
+ ```ts
81
+ import { AgentClient, TransferEvent } from '@ideascol/agents-generator-sdk';
82
+
83
+ const client = new AgentClient({
84
+ apiUrl: 'https://api.agentsgenerator.dev',
85
+ apiToken: 'YOUR_API_TOKEN',
86
+ });
87
+
88
+ const abort = client.sendMessageWithStreaming(
89
+ 'conversation-id',
90
+ { content: 'Hello!' },
91
+ {
92
+ onMessage: (content: string) => {
93
+ console.log('Message update:', content);
94
+ },
95
+ onDone: (messageId: string) => {
96
+ console.log('Message completed:', messageId);
97
+ },
98
+ onTransfer: (transfer: TransferEvent) => {
99
+ console.log('Transfer detected!');
100
+ console.log(` From: ${transfer.from_agent}`);
101
+ console.log(` To: ${transfer.to_agent}`);
102
+ console.log(` Reason: ${transfer.reason}`);
103
+ },
104
+ onError: (error: Error) => {
105
+ console.error('Error:', error);
106
+ }
107
+ }
108
+ );
109
+
110
+ // To abort the stream:
111
+ // abort();
112
+ ```
113
+
114
+ ### TypeScript Types
115
+
116
+ ```ts
117
+ interface SendMessageResponse {
118
+ status: string;
119
+ message: string;
120
+ message_id?: string;
121
+ transfers?: TransferEvent[];
122
+ }
123
+
124
+ interface TransferEvent {
125
+ from_agent?: string;
126
+ to_agent?: string;
127
+ reason?: string;
128
+ }
129
+
130
+ interface StreamCallbacks {
131
+ onMessage?: (content: string) => void;
132
+ onDone?: (messageId: string) => void;
133
+ onError?: (error: Error) => void;
134
+ onTransfer?: (transfer: TransferEvent) => void;
135
+ }
136
+ ```
137
+
42
138
  ## Quick start
43
139
  ```bash
44
140
  # Using npm
package/dist/bin/cli.js CHANGED
@@ -910,6 +910,18 @@ class AdminAgentsService {
910
910
  }
911
911
  });
912
912
  }
913
+ static getWorkspaceConversationsTotal(workspaceId) {
914
+ return request(OpenAPI, {
915
+ method: "GET",
916
+ url: "/agents/conversations/total",
917
+ query: {
918
+ workspace_id: workspaceId
919
+ },
920
+ errors: {
921
+ 422: `Validation Error`
922
+ }
923
+ });
924
+ }
913
925
  static initializeAgent(agentId) {
914
926
  return request(OpenAPI, {
915
927
  method: "POST",
@@ -955,6 +967,21 @@ class AdminAgentsService {
955
967
  }
956
968
  });
957
969
  }
970
+ static getAgentConversationsTotal(agentId, workspaceId) {
971
+ return request(OpenAPI, {
972
+ method: "GET",
973
+ url: "/agents/{agent_id}/conversations/total",
974
+ path: {
975
+ agent_id: agentId
976
+ },
977
+ query: {
978
+ workspace_id: workspaceId
979
+ },
980
+ errors: {
981
+ 422: `Validation Error`
982
+ }
983
+ });
984
+ }
958
985
  static visualizeAgent(agentId, userId, format = "png") {
959
986
  return request(OpenAPI, {
960
987
  method: "GET",
@@ -1502,6 +1529,18 @@ class AgentService {
1502
1529
  }
1503
1530
  });
1504
1531
  }
1532
+ static getWorkspaceConversationsTotal(workspaceId) {
1533
+ return request(OpenAPI, {
1534
+ method: "GET",
1535
+ url: "/agents/conversations/total",
1536
+ query: {
1537
+ workspace_id: workspaceId
1538
+ },
1539
+ errors: {
1540
+ 422: `Validation Error`
1541
+ }
1542
+ });
1543
+ }
1505
1544
  static initializeAgent(agentId) {
1506
1545
  return request(OpenAPI, {
1507
1546
  method: "POST",
@@ -1547,6 +1586,21 @@ class AgentService {
1547
1586
  }
1548
1587
  });
1549
1588
  }
1589
+ static getAgentConversationsTotal(agentId, workspaceId) {
1590
+ return request(OpenAPI, {
1591
+ method: "GET",
1592
+ url: "/agents/{agent_id}/conversations/total",
1593
+ path: {
1594
+ agent_id: agentId
1595
+ },
1596
+ query: {
1597
+ workspace_id: workspaceId
1598
+ },
1599
+ errors: {
1600
+ 422: `Validation Error`
1601
+ }
1602
+ });
1603
+ }
1550
1604
  static visualizeAgent(agentId, userId, format = "png") {
1551
1605
  return request(OpenAPI, {
1552
1606
  method: "GET",
@@ -2229,7 +2283,7 @@ class AgentClient {
2229
2283
  return ConversationsServiceStream.addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, callbacks);
2230
2284
  }
2231
2285
  sendMessage(conversationId, requestBody) {
2232
- return ConversationsServiceStream.addMessage(conversationId, requestBody, "text/plain");
2286
+ return PublicConversationsServiceExtended.sendMessage(conversationId, requestBody);
2233
2287
  }
2234
2288
  }
2235
2289
  var ConversationsServiceStream, PublicConversationsServiceExtended, lib_default;
@@ -2360,6 +2414,8 @@ var init_lib = __esm(() => {
2360
2414
  callbacks.onMessage(fullMessage);
2361
2415
  } else if (data.type === "done" && data.message_id && callbacks.onDone) {
2362
2416
  callbacks.onDone(data.message_id);
2417
+ } else if (data.type === "transfer" && data.transfer && callbacks.onTransfer) {
2418
+ callbacks.onTransfer(data.transfer);
2363
2419
  }
2364
2420
  } catch (e) {
2365
2421
  console.error("Error al parsear JSON del evento:", e);
@@ -2417,7 +2473,46 @@ var init_lib = __esm(() => {
2417
2473
  return ConversationsServiceStream.addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, callbacks);
2418
2474
  }
2419
2475
  static sendMessage(conversationId, requestBody) {
2420
- return ConversationsServiceStream.addMessage(conversationId, requestBody);
2476
+ return new Promise((resolve2, reject) => {
2477
+ let fullMessage = "";
2478
+ let messageId = "";
2479
+ const transfers = [];
2480
+ let streamCompleted = false;
2481
+ let timeoutId;
2482
+ const abort = ConversationsServiceStream.addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, {
2483
+ onMessage: (content) => {
2484
+ fullMessage = content;
2485
+ },
2486
+ onDone: (id) => {
2487
+ messageId = id;
2488
+ streamCompleted = true;
2489
+ if (timeoutId) {
2490
+ clearTimeout(timeoutId);
2491
+ }
2492
+ resolve2({
2493
+ status: "success",
2494
+ message: fullMessage,
2495
+ message_id: messageId || undefined,
2496
+ transfers: transfers.length > 0 ? transfers : undefined
2497
+ });
2498
+ },
2499
+ onTransfer: (transfer) => {
2500
+ transfers.push(transfer);
2501
+ },
2502
+ onError: (error) => {
2503
+ if (timeoutId) {
2504
+ clearTimeout(timeoutId);
2505
+ }
2506
+ reject(error);
2507
+ }
2508
+ });
2509
+ timeoutId = setTimeout(() => {
2510
+ if (!streamCompleted) {
2511
+ abort();
2512
+ reject(new Error("Message send timeout after 60 seconds"));
2513
+ }
2514
+ }, 60000);
2515
+ });
2421
2516
  }
2422
2517
  };
2423
2518
  lib_default = AgentClient;
package/dist/index.js CHANGED
@@ -478,6 +478,18 @@ class AdminAgentsService {
478
478
  }
479
479
  });
480
480
  }
481
+ static getWorkspaceConversationsTotal(workspaceId) {
482
+ return request(OpenAPI, {
483
+ method: "GET",
484
+ url: "/agents/conversations/total",
485
+ query: {
486
+ workspace_id: workspaceId
487
+ },
488
+ errors: {
489
+ 422: `Validation Error`
490
+ }
491
+ });
492
+ }
481
493
  static initializeAgent(agentId) {
482
494
  return request(OpenAPI, {
483
495
  method: "POST",
@@ -523,6 +535,21 @@ class AdminAgentsService {
523
535
  }
524
536
  });
525
537
  }
538
+ static getAgentConversationsTotal(agentId, workspaceId) {
539
+ return request(OpenAPI, {
540
+ method: "GET",
541
+ url: "/agents/{agent_id}/conversations/total",
542
+ path: {
543
+ agent_id: agentId
544
+ },
545
+ query: {
546
+ workspace_id: workspaceId
547
+ },
548
+ errors: {
549
+ 422: `Validation Error`
550
+ }
551
+ });
552
+ }
526
553
  static visualizeAgent(agentId, userId, format = "png") {
527
554
  return request(OpenAPI, {
528
555
  method: "GET",
@@ -1070,6 +1097,18 @@ class AgentService {
1070
1097
  }
1071
1098
  });
1072
1099
  }
1100
+ static getWorkspaceConversationsTotal(workspaceId) {
1101
+ return request(OpenAPI, {
1102
+ method: "GET",
1103
+ url: "/agents/conversations/total",
1104
+ query: {
1105
+ workspace_id: workspaceId
1106
+ },
1107
+ errors: {
1108
+ 422: `Validation Error`
1109
+ }
1110
+ });
1111
+ }
1073
1112
  static initializeAgent(agentId) {
1074
1113
  return request(OpenAPI, {
1075
1114
  method: "POST",
@@ -1115,6 +1154,21 @@ class AgentService {
1115
1154
  }
1116
1155
  });
1117
1156
  }
1157
+ static getAgentConversationsTotal(agentId, workspaceId) {
1158
+ return request(OpenAPI, {
1159
+ method: "GET",
1160
+ url: "/agents/{agent_id}/conversations/total",
1161
+ path: {
1162
+ agent_id: agentId
1163
+ },
1164
+ query: {
1165
+ workspace_id: workspaceId
1166
+ },
1167
+ errors: {
1168
+ 422: `Validation Error`
1169
+ }
1170
+ });
1171
+ }
1118
1172
  static visualizeAgent(agentId, userId, format = "png") {
1119
1173
  return request(OpenAPI, {
1120
1174
  method: "GET",
@@ -1797,7 +1851,7 @@ class AgentClient {
1797
1851
  return ConversationsServiceStream.addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, callbacks);
1798
1852
  }
1799
1853
  sendMessage(conversationId, requestBody) {
1800
- return ConversationsServiceStream.addMessage(conversationId, requestBody, "text/plain");
1854
+ return PublicConversationsServiceExtended.sendMessage(conversationId, requestBody);
1801
1855
  }
1802
1856
  }
1803
1857
  var ConversationsServiceStream, PublicConversationsServiceExtended, lib_default;
@@ -1928,6 +1982,8 @@ var init_lib = __esm(() => {
1928
1982
  callbacks.onMessage(fullMessage);
1929
1983
  } else if (data.type === "done" && data.message_id && callbacks.onDone) {
1930
1984
  callbacks.onDone(data.message_id);
1985
+ } else if (data.type === "transfer" && data.transfer && callbacks.onTransfer) {
1986
+ callbacks.onTransfer(data.transfer);
1931
1987
  }
1932
1988
  } catch (e) {
1933
1989
  console.error("Error al parsear JSON del evento:", e);
@@ -1985,7 +2041,46 @@ var init_lib = __esm(() => {
1985
2041
  return ConversationsServiceStream.addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, callbacks);
1986
2042
  }
1987
2043
  static sendMessage(conversationId, requestBody) {
1988
- return ConversationsServiceStream.addMessage(conversationId, requestBody);
2044
+ return new Promise((resolve2, reject) => {
2045
+ let fullMessage = "";
2046
+ let messageId = "";
2047
+ const transfers = [];
2048
+ let streamCompleted = false;
2049
+ let timeoutId;
2050
+ const abort = ConversationsServiceStream.addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, {
2051
+ onMessage: (content) => {
2052
+ fullMessage = content;
2053
+ },
2054
+ onDone: (id) => {
2055
+ messageId = id;
2056
+ streamCompleted = true;
2057
+ if (timeoutId) {
2058
+ clearTimeout(timeoutId);
2059
+ }
2060
+ resolve2({
2061
+ status: "success",
2062
+ message: fullMessage,
2063
+ message_id: messageId || undefined,
2064
+ transfers: transfers.length > 0 ? transfers : undefined
2065
+ });
2066
+ },
2067
+ onTransfer: (transfer) => {
2068
+ transfers.push(transfer);
2069
+ },
2070
+ onError: (error) => {
2071
+ if (timeoutId) {
2072
+ clearTimeout(timeoutId);
2073
+ }
2074
+ reject(error);
2075
+ }
2076
+ });
2077
+ timeoutId = setTimeout(() => {
2078
+ if (!streamCompleted) {
2079
+ abort();
2080
+ reject(new Error("Message send timeout after 60 seconds"));
2081
+ }
2082
+ }, 60000);
2083
+ });
1989
2084
  }
1990
2085
  };
1991
2086
  lib_default = AgentClient;
@@ -48,6 +48,14 @@ export declare class AdminAgentsService {
48
48
  * @throws ApiError
49
49
  */
50
50
  static deleteAgent(agentId: string, workspaceId?: (string | null)): CancelablePromise<Record<string, any>>;
51
+ /**
52
+ * Get Workspace Conversations Total
53
+ * Get the total count of conversations for all agents in a workspace.
54
+ * @param workspaceId
55
+ * @returns any Successful Response
56
+ * @throws ApiError
57
+ */
58
+ static getWorkspaceConversationsTotal(workspaceId?: (string | null)): CancelablePromise<Record<string, any>>;
51
59
  /**
52
60
  * Initialize Agent
53
61
  * @param agentId
@@ -75,6 +83,15 @@ export declare class AdminAgentsService {
75
83
  * @throws ApiError
76
84
  */
77
85
  static getAgentStructure(agentId: string, userId?: (string | null)): CancelablePromise<Record<string, any>>;
86
+ /**
87
+ * Get Agent Conversations Total
88
+ * Get the total count of conversations for a specific agent.
89
+ * @param agentId
90
+ * @param workspaceId
91
+ * @returns any Successful Response
92
+ * @throws ApiError
93
+ */
94
+ static getAgentConversationsTotal(agentId: string, workspaceId?: (string | null)): CancelablePromise<Record<string, any>>;
78
95
  /**
79
96
  * Visualize Agent
80
97
  * @param agentId
@@ -48,6 +48,14 @@ export declare class AgentService {
48
48
  * @throws ApiError
49
49
  */
50
50
  static deleteAgent(agentId: string, workspaceId?: (string | null)): CancelablePromise<Record<string, any>>;
51
+ /**
52
+ * Get Workspace Conversations Total
53
+ * Get the total count of conversations for all agents in a workspace.
54
+ * @param workspaceId
55
+ * @returns any Successful Response
56
+ * @throws ApiError
57
+ */
58
+ static getWorkspaceConversationsTotal(workspaceId?: (string | null)): CancelablePromise<Record<string, any>>;
51
59
  /**
52
60
  * Initialize Agent
53
61
  * @param agentId
@@ -75,6 +83,15 @@ export declare class AgentService {
75
83
  * @throws ApiError
76
84
  */
77
85
  static getAgentStructure(agentId: string, userId?: (string | null)): CancelablePromise<Record<string, any>>;
86
+ /**
87
+ * Get Agent Conversations Total
88
+ * Get the total count of conversations for a specific agent.
89
+ * @param agentId
90
+ * @param workspaceId
91
+ * @returns any Successful Response
92
+ * @throws ApiError
93
+ */
94
+ static getAgentConversationsTotal(agentId: string, workspaceId?: (string | null)): CancelablePromise<Record<string, any>>;
78
95
  /**
79
96
  * Visualize Agent
80
97
  * @param agentId
@@ -4,11 +4,24 @@ export interface StreamEvent {
4
4
  type: string;
5
5
  content?: string;
6
6
  message_id?: string;
7
+ transfer?: TransferEvent;
8
+ }
9
+ export interface TransferEvent {
10
+ from_agent?: string;
11
+ to_agent?: string;
12
+ reason?: string;
7
13
  }
8
14
  export interface StreamCallbacks {
9
15
  onMessage?: (content: string) => void;
10
16
  onDone?: (messageId: string) => void;
11
17
  onError?: (error: Error) => void;
18
+ onTransfer?: (transfer: TransferEvent) => void;
19
+ }
20
+ export interface SendMessageResponse {
21
+ status: string;
22
+ message: string;
23
+ message_id?: string;
24
+ transfers?: TransferEvent[];
12
25
  }
13
26
  declare class ConversationsServiceStream extends ConversationsService {
14
27
  constructor();
@@ -23,11 +36,13 @@ declare class ConversationsServiceStream extends ConversationsService {
23
36
  }
24
37
  declare class PublicConversationsServiceExtended extends PublicConversationsService {
25
38
  static sendMessageWithStreaming(conversationId: string, requestBody: MessageCreate, callbacks: StreamCallbacks): () => void;
26
- static sendMessage(conversationId: string, requestBody: MessageCreate): CancelablePromise<{
27
- status: string;
28
- message: string;
29
- message_id?: string;
30
- }>;
39
+ /**
40
+ * Send a message synchronously using streaming internally to capture transfers
41
+ * @param conversationId The ID of the conversation
42
+ * @param requestBody The message data to send
43
+ * @returns Promise with the complete response including transfers
44
+ */
45
+ static sendMessage(conversationId: string, requestBody: MessageCreate): Promise<SendMessageResponse>;
31
46
  }
32
47
  export declare class AgentClient {
33
48
  admin: {
@@ -82,14 +97,11 @@ export declare class AgentClient {
82
97
  */
83
98
  sendMessageWithStreaming(conversationId: string, requestBody: MessageCreate, callbacks: StreamCallbacks): () => void;
84
99
  /**
85
- * sendMessage: Sends a message to a conversation without streaming
86
- * @returns CancelablePromise with the response
100
+ * sendMessage: Sends a message to a conversation with transfer detection
101
+ * Uses streaming internally to capture transfer events
102
+ * @returns Promise with the complete response including transfers
87
103
  * Use client.public.conversations.sendMessage instead
88
104
  */
89
- sendMessage(conversationId: string, requestBody: MessageCreate): CancelablePromise<{
90
- status: string;
91
- message: string;
92
- message_id?: string;
93
- }>;
105
+ sendMessage(conversationId: string, requestBody: MessageCreate): Promise<SendMessageResponse>;
94
106
  }
95
107
  export default AgentClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ideascol/agents-generator-sdk",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "bun test",