@ideascol/agents-generator-sdk 0.3.4 → 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 +96 -0
- package/dist/bin/cli.js +43 -2
- package/dist/index.js +43 -2
- package/dist/lib/index.d.ts +24 -12
- package/package.json +1 -1
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
|
@@ -2283,7 +2283,7 @@ class AgentClient {
|
|
|
2283
2283
|
return ConversationsServiceStream.addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, callbacks);
|
|
2284
2284
|
}
|
|
2285
2285
|
sendMessage(conversationId, requestBody) {
|
|
2286
|
-
return
|
|
2286
|
+
return PublicConversationsServiceExtended.sendMessage(conversationId, requestBody);
|
|
2287
2287
|
}
|
|
2288
2288
|
}
|
|
2289
2289
|
var ConversationsServiceStream, PublicConversationsServiceExtended, lib_default;
|
|
@@ -2414,6 +2414,8 @@ var init_lib = __esm(() => {
|
|
|
2414
2414
|
callbacks.onMessage(fullMessage);
|
|
2415
2415
|
} else if (data.type === "done" && data.message_id && callbacks.onDone) {
|
|
2416
2416
|
callbacks.onDone(data.message_id);
|
|
2417
|
+
} else if (data.type === "transfer" && data.transfer && callbacks.onTransfer) {
|
|
2418
|
+
callbacks.onTransfer(data.transfer);
|
|
2417
2419
|
}
|
|
2418
2420
|
} catch (e) {
|
|
2419
2421
|
console.error("Error al parsear JSON del evento:", e);
|
|
@@ -2471,7 +2473,46 @@ var init_lib = __esm(() => {
|
|
|
2471
2473
|
return ConversationsServiceStream.addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, callbacks);
|
|
2472
2474
|
}
|
|
2473
2475
|
static sendMessage(conversationId, requestBody) {
|
|
2474
|
-
return
|
|
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
|
+
});
|
|
2475
2516
|
}
|
|
2476
2517
|
};
|
|
2477
2518
|
lib_default = AgentClient;
|
package/dist/index.js
CHANGED
|
@@ -1851,7 +1851,7 @@ class AgentClient {
|
|
|
1851
1851
|
return ConversationsServiceStream.addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, callbacks);
|
|
1852
1852
|
}
|
|
1853
1853
|
sendMessage(conversationId, requestBody) {
|
|
1854
|
-
return
|
|
1854
|
+
return PublicConversationsServiceExtended.sendMessage(conversationId, requestBody);
|
|
1855
1855
|
}
|
|
1856
1856
|
}
|
|
1857
1857
|
var ConversationsServiceStream, PublicConversationsServiceExtended, lib_default;
|
|
@@ -1982,6 +1982,8 @@ var init_lib = __esm(() => {
|
|
|
1982
1982
|
callbacks.onMessage(fullMessage);
|
|
1983
1983
|
} else if (data.type === "done" && data.message_id && callbacks.onDone) {
|
|
1984
1984
|
callbacks.onDone(data.message_id);
|
|
1985
|
+
} else if (data.type === "transfer" && data.transfer && callbacks.onTransfer) {
|
|
1986
|
+
callbacks.onTransfer(data.transfer);
|
|
1985
1987
|
}
|
|
1986
1988
|
} catch (e) {
|
|
1987
1989
|
console.error("Error al parsear JSON del evento:", e);
|
|
@@ -2039,7 +2041,46 @@ var init_lib = __esm(() => {
|
|
|
2039
2041
|
return ConversationsServiceStream.addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, callbacks);
|
|
2040
2042
|
}
|
|
2041
2043
|
static sendMessage(conversationId, requestBody) {
|
|
2042
|
-
return
|
|
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
|
+
});
|
|
2043
2084
|
}
|
|
2044
2085
|
};
|
|
2045
2086
|
lib_default = AgentClient;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
86
|
-
*
|
|
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):
|
|
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;
|