@wundr.io/autogen-orchestrator 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.
@@ -0,0 +1,327 @@
1
+ /**
2
+ * GroupChatManager - Core orchestration for AutoGen-style multi-agent conversations
3
+ *
4
+ * Implements conversational patterns for coordinating multiple AI agents in a
5
+ * group chat setting with configurable speaker selection and termination conditions.
6
+ */
7
+ import { EventEmitter } from 'eventemitter3';
8
+ import type { NestedChatResult } from './nested-chat';
9
+ import type { Message, ChatParticipant, ChatContext, ChatResult, ChatStatus, ChatMetrics, ChatError, GroupChatConfig, TerminationCondition, NestedChatConfig, CreateMessageOptions, AddParticipantOptions, StartChatOptions, ParticipantStatus } from './types';
10
+ /**
11
+ * Events emitted by the GroupChatManager
12
+ */
13
+ export interface GroupChatEvents {
14
+ 'chat:started': (data: {
15
+ chatId: string;
16
+ config: GroupChatConfig;
17
+ }) => void;
18
+ 'chat:ended': (data: {
19
+ chatId: string;
20
+ result: ChatResult;
21
+ }) => void;
22
+ 'chat:error': (data: {
23
+ chatId: string;
24
+ error: ChatError;
25
+ }) => void;
26
+ 'message:sent': (data: {
27
+ chatId: string;
28
+ message: Message;
29
+ }) => void;
30
+ 'message:received': (data: {
31
+ chatId: string;
32
+ message: Message;
33
+ }) => void;
34
+ 'speaker:selected': (data: {
35
+ chatId: string;
36
+ speaker: string;
37
+ reason?: string;
38
+ }) => void;
39
+ 'round:started': (data: {
40
+ chatId: string;
41
+ round: number;
42
+ }) => void;
43
+ 'round:ended': (data: {
44
+ chatId: string;
45
+ round: number;
46
+ }) => void;
47
+ 'termination:triggered': (data: {
48
+ chatId: string;
49
+ reason: string;
50
+ }) => void;
51
+ 'nested:started': (data: {
52
+ chatId: string;
53
+ nestedChatId: string;
54
+ }) => void;
55
+ 'nested:ended': (data: {
56
+ chatId: string;
57
+ nestedChatId: string;
58
+ result: NestedChatResult;
59
+ }) => void;
60
+ }
61
+ /**
62
+ * Response generator function type
63
+ * Used to generate responses for participants
64
+ */
65
+ export type ResponseGenerator = (participant: ChatParticipant, messages: Message[], context: ChatContext) => Promise<string>;
66
+ /**
67
+ * GroupChatManager - Orchestrates multi-agent conversations
68
+ */
69
+ export declare class GroupChatManager extends EventEmitter<GroupChatEvents> {
70
+ private config;
71
+ private participants;
72
+ private messages;
73
+ private context;
74
+ private status;
75
+ private startTime?;
76
+ private endTime?;
77
+ private chatId;
78
+ private speakerManager;
79
+ private terminationManager;
80
+ private nestedChatManager;
81
+ private responseGenerator?;
82
+ private metrics;
83
+ private nestedResults;
84
+ /**
85
+ * Create a new GroupChatManager
86
+ * @param config - Group chat configuration
87
+ */
88
+ constructor(config: GroupChatConfig);
89
+ /**
90
+ * Setup event forwarding from nested chat manager
91
+ */
92
+ private setupNestedChatEvents;
93
+ /**
94
+ * Set the response generator function
95
+ * @param generator - Function to generate participant responses
96
+ */
97
+ setResponseGenerator(generator: ResponseGenerator): void;
98
+ /**
99
+ * Start the group chat
100
+ * @param options - Optional start options
101
+ * @returns Chat result when completed
102
+ */
103
+ start(options?: StartChatOptions): Promise<ChatResult>;
104
+ /**
105
+ * Run the main conversation loop
106
+ * @param options - Start options
107
+ * @returns Chat result
108
+ */
109
+ private runConversationLoop;
110
+ /**
111
+ * Generate a response for a participant
112
+ * @param participant - Participant to generate response for
113
+ * @returns Generated response content
114
+ */
115
+ private generateResponse;
116
+ /**
117
+ * Generate a placeholder response when no generator is set
118
+ * @param participant - Participant to generate for
119
+ * @returns Placeholder response
120
+ */
121
+ private generatePlaceholderResponse;
122
+ /**
123
+ * Update metrics after a response
124
+ * @param participantName - Name of the participant
125
+ * @param latencyMs - Response latency
126
+ * @param tokenEstimate - Estimated token count
127
+ */
128
+ private updateMetrics;
129
+ /**
130
+ * Check if a message triggers a nested chat
131
+ * @param message - Message to check
132
+ */
133
+ private checkNestedChatTriggers;
134
+ /**
135
+ * Run a nested chat session
136
+ * @param config - Nested chat configuration
137
+ * @param triggerMessageId - ID of the triggering message
138
+ */
139
+ private runNestedChat;
140
+ /**
141
+ * Add a message to the chat
142
+ * @param options - Message options
143
+ * @returns Created message
144
+ */
145
+ addMessage(options: CreateMessageOptions): Promise<Message>;
146
+ /**
147
+ * Add a participant to the chat
148
+ * @param options - Participant options
149
+ * @returns Created participant
150
+ */
151
+ addParticipant(options: AddParticipantOptions): ChatParticipant;
152
+ /**
153
+ * Remove a participant from the chat
154
+ * @param name - Participant name
155
+ */
156
+ removeParticipant(name: string): void;
157
+ /**
158
+ * Update a participant's status
159
+ * @param name - Participant name
160
+ * @param status - New status
161
+ */
162
+ updateParticipantStatus(name: string, status: ParticipantStatus): void;
163
+ /**
164
+ * Add a termination condition
165
+ * @param condition - Condition to add
166
+ */
167
+ addTerminationCondition(condition: TerminationCondition): void;
168
+ /**
169
+ * Add a nested chat configuration
170
+ * @param config - Nested chat config
171
+ */
172
+ addNestedChatConfig(config: NestedChatConfig): void;
173
+ /**
174
+ * Pause the chat
175
+ */
176
+ pause(): void;
177
+ /**
178
+ * Resume the chat
179
+ */
180
+ resume(): void;
181
+ /**
182
+ * Stop the chat
183
+ * @param reason - Reason for stopping
184
+ * @returns Chat result
185
+ */
186
+ stop(reason?: string): Promise<ChatResult>;
187
+ /**
188
+ * End the chat and produce a result
189
+ * @param status - Final status
190
+ * @param reason - Termination reason
191
+ * @returns Chat result
192
+ */
193
+ private endChat;
194
+ /**
195
+ * Handle an error during chat execution
196
+ * @param error - Error that occurred
197
+ * @returns Chat result with error
198
+ */
199
+ private handleError;
200
+ /**
201
+ * Generate a summary of the conversation
202
+ * @returns Summary string
203
+ */
204
+ private generateSummary;
205
+ /**
206
+ * Emit a chat event
207
+ * @param type - Event type
208
+ * @param data - Event data typed based on event type
209
+ */
210
+ private emitEvent;
211
+ /**
212
+ * Get the current chat status
213
+ * @returns Current status
214
+ */
215
+ getStatus(): ChatStatus;
216
+ /**
217
+ * Get the chat ID
218
+ * @returns Chat ID
219
+ */
220
+ getChatId(): string;
221
+ /**
222
+ * Get all messages
223
+ * @returns Message array
224
+ */
225
+ getMessages(): Message[];
226
+ /**
227
+ * Get all participants
228
+ * @returns Participant array
229
+ */
230
+ getParticipants(): ChatParticipant[];
231
+ /**
232
+ * Get the current context
233
+ * @returns Chat context
234
+ */
235
+ getContext(): ChatContext;
236
+ /**
237
+ * Get current metrics
238
+ * @returns Chat metrics
239
+ */
240
+ getMetrics(): ChatMetrics;
241
+ /**
242
+ * Update context state
243
+ * @param key - State key
244
+ * @param value - State value (typed for common use cases)
245
+ */
246
+ updateState<T extends string | number | boolean | object | null>(key: string, value: T): void;
247
+ /**
248
+ * Get context state value
249
+ * @param key - State key
250
+ * @returns State value
251
+ */
252
+ getState<T>(key: string): T | undefined;
253
+ }
254
+ /**
255
+ * Builder for creating GroupChatManager instances
256
+ */
257
+ export declare class GroupChatBuilder {
258
+ private config;
259
+ /**
260
+ * Set the chat name
261
+ * @param name - Chat name
262
+ */
263
+ withName(name: string): this;
264
+ /**
265
+ * Set the chat description
266
+ * @param description - Chat description
267
+ */
268
+ withDescription(description: string): this;
269
+ /**
270
+ * Add a participant
271
+ * @param participant - Participant to add
272
+ */
273
+ withParticipant(participant: ChatParticipant): this;
274
+ /**
275
+ * Set the speaker selection method
276
+ * @param method - Selection method
277
+ */
278
+ withSpeakerSelection(method: GroupChatConfig['speakerSelectionMethod']): this;
279
+ /**
280
+ * Set maximum rounds
281
+ * @param maxRounds - Maximum rounds
282
+ */
283
+ withMaxRounds(maxRounds: number): this;
284
+ /**
285
+ * Set maximum messages
286
+ * @param maxMessages - Maximum messages
287
+ */
288
+ withMaxMessages(maxMessages: number): this;
289
+ /**
290
+ * Add a termination condition
291
+ * @param condition - Termination condition
292
+ */
293
+ withTerminationCondition(condition: TerminationCondition): this;
294
+ /**
295
+ * Enable nested chats
296
+ */
297
+ withNestedChats(): this;
298
+ /**
299
+ * Add a nested chat configuration
300
+ * @param config - Nested chat config
301
+ */
302
+ withNestedChatConfig(config: NestedChatConfig): this;
303
+ /**
304
+ * Set the admin name
305
+ * @param name - Admin name
306
+ */
307
+ withAdmin(name: string): this;
308
+ /**
309
+ * Set timeout
310
+ * @param timeoutMs - Timeout in milliseconds
311
+ */
312
+ withTimeout(timeoutMs: number): this;
313
+ /**
314
+ * Build the GroupChatManager
315
+ * @returns Configured GroupChatManager
316
+ */
317
+ build(): GroupChatManager;
318
+ }
319
+ /**
320
+ * Create a simple participant configuration
321
+ * @param name - Participant name
322
+ * @param systemPrompt - System prompt
323
+ * @param capabilities - Participant capabilities
324
+ * @returns Participant configuration
325
+ */
326
+ export declare function createParticipant(name: string, systemPrompt: string, capabilities?: string[]): ChatParticipant;
327
+ //# sourceMappingURL=group-chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-chat.d.ts","sourceRoot":"","sources":["../src/group-chat.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAQ7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EACV,OAAO,EACP,eAAe,EACf,WAAW,EACX,UAAU,EACV,UAAU,EACV,WAAW,EACX,SAAS,EAIT,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,cAAc,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,eAAe,CAAA;KAAE,KAAK,IAAI,CAAC;IAC5E,YAAY,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,CAAA;KAAE,KAAK,IAAI,CAAC;IACrE,YAAY,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,SAAS,CAA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