@serenity-star/sdk 1.0.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.d.mts +757 -0
- package/dist/index.d.ts +757 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +31 -0
- package/readme.md +473 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,757 @@
|
|
|
1
|
+
declare class EventEmitter<T extends Record<string, (...args: any[]) => void>> {
|
|
2
|
+
private listeners;
|
|
3
|
+
on<K extends keyof T>(eventName: K, listener: T[K]): this;
|
|
4
|
+
emit<K extends keyof T>(eventName: K, ...args: Parameters<T[K]>): void;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare enum VendorEnum {
|
|
8
|
+
OpenAI = 0,
|
|
9
|
+
Azure = 1,
|
|
10
|
+
Mistral = 2,
|
|
11
|
+
HuggingFace = 3,
|
|
12
|
+
Together = 4,
|
|
13
|
+
Groq = 5,
|
|
14
|
+
Anthropic = 6,
|
|
15
|
+
Google = 7,
|
|
16
|
+
Mock = 8,
|
|
17
|
+
Serenity = 9,
|
|
18
|
+
Cerebras = 10,
|
|
19
|
+
Replicate = 11,
|
|
20
|
+
AmazonBedrock = 12,
|
|
21
|
+
GoogleVertex = 13,
|
|
22
|
+
OpenRouter = 14,
|
|
23
|
+
xAI = 15,
|
|
24
|
+
IBM = 16,
|
|
25
|
+
DeepSeek = 17,
|
|
26
|
+
Nvidia = 18
|
|
27
|
+
}
|
|
28
|
+
type ProxyExecutionMessage = {
|
|
29
|
+
/** The role of the message sender (e.g., 'system', 'user', 'assistant') */
|
|
30
|
+
role: "system" | "user" | "assistant";
|
|
31
|
+
/** The actual message content */
|
|
32
|
+
content: string;
|
|
33
|
+
/** Array of unique ids for volatile knowledge files */
|
|
34
|
+
volatileKnowledgeIds?: string[];
|
|
35
|
+
};
|
|
36
|
+
type ProxyExecutionOptions = {
|
|
37
|
+
/** The identifier of the AI model to use (e.g., 'gpt-4', 'claude-2')
|
|
38
|
+
* @see https://docs.serenitystar.ai/docs/serenity-aihub/ai-models/available-models/ for available models
|
|
39
|
+
*/
|
|
40
|
+
model: string;
|
|
41
|
+
/** Array of messages representing the conversation history */
|
|
42
|
+
messages: ProxyExecutionMessage[];
|
|
43
|
+
/** Reduces repetition by lowering the likelihood of using tokens that have appeared recently. Range: -2.0 to 2.0 */
|
|
44
|
+
frequency_penalty?: number;
|
|
45
|
+
/** The maximum number of tokens to generate in the response */
|
|
46
|
+
max_tokens?: number;
|
|
47
|
+
/** Increases diversity by penalizing tokens that have appeared in the text at all. Range: -2.0 to 2.0 */
|
|
48
|
+
presence_penalty?: number;
|
|
49
|
+
/** Controls randomness in the output. Higher values (e.g., 0.8) make output more random, lower values (e.g., 0.2) make it more focused. Range: 0-1 */
|
|
50
|
+
temperature?: number;
|
|
51
|
+
/** Alternative to temperature. Limits cumulative probability of tokens considered. Range: 0-1 */
|
|
52
|
+
top_p?: number;
|
|
53
|
+
/** Limits the number of tokens to consider at each step. Used by some models */
|
|
54
|
+
top_k?: number;
|
|
55
|
+
/** The AI vendor/provider to use for this request */
|
|
56
|
+
vendor?: VendorEnum;
|
|
57
|
+
/** Identifier for the user making the request */
|
|
58
|
+
userIdentifier?: string;
|
|
59
|
+
/** Identifier for the user's group or organization */
|
|
60
|
+
groupIdentifier?: string;
|
|
61
|
+
/** Whether to enable vision/image understanding capabilities */
|
|
62
|
+
useVision?: boolean;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Options for configuring the Serenity client.
|
|
67
|
+
*/
|
|
68
|
+
type SerenityClientOptions = {
|
|
69
|
+
/**
|
|
70
|
+
* The API key used for authenticating requests to the Serenity API.
|
|
71
|
+
*/
|
|
72
|
+
apiKey: string;
|
|
73
|
+
/**
|
|
74
|
+
* The base URL of the Serenity API.
|
|
75
|
+
*/
|
|
76
|
+
baseUrl?: string;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Base options for executing any type of agent.
|
|
80
|
+
*/
|
|
81
|
+
type AgentExecutionOptions = {
|
|
82
|
+
/**
|
|
83
|
+
* Optional identifier for the user initiating the execution.
|
|
84
|
+
*/
|
|
85
|
+
userIdentifier?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Optional version number of the agent to execute.
|
|
88
|
+
*/
|
|
89
|
+
agentVersion?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Optional channel identifier where the execution is taking place.
|
|
92
|
+
*/
|
|
93
|
+
channel?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Optional array of volatile knowledge IDs to include in the execution context.
|
|
96
|
+
*/
|
|
97
|
+
volatileKnowledgeIds?: string[];
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Extends AgentExecutionOptions to include input parameters for agents that support them.
|
|
101
|
+
*/
|
|
102
|
+
type AgentExecutionOptionsWithParameters = AgentExecutionOptions & {
|
|
103
|
+
/**
|
|
104
|
+
* Optional key-value pairs of input parameters specific to the agent.
|
|
105
|
+
*/
|
|
106
|
+
inputParameters?: {
|
|
107
|
+
[key: string]: any;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Maps agent types to their specific execution options for conversational agents.
|
|
112
|
+
*
|
|
113
|
+
* @remarks
|
|
114
|
+
* Both assistant and copilot agents support input parameters in addition to base execution options.
|
|
115
|
+
*/
|
|
116
|
+
type ConversationalAgentExecutionOptionsMap = {
|
|
117
|
+
"assistant": AgentExecutionOptionsWithParameters;
|
|
118
|
+
"copilot": AgentExecutionOptionsWithParameters;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Maps agent types to their specific execution options for system agents.
|
|
122
|
+
*
|
|
123
|
+
* @remarks
|
|
124
|
+
* - Chat-completion agents require message content
|
|
125
|
+
* - Proxy agents have specific proxy execution options
|
|
126
|
+
*/
|
|
127
|
+
type SystemAgentExecutionOptionsMap = {
|
|
128
|
+
"activity": AgentExecutionOptionsWithParameters;
|
|
129
|
+
"plan": AgentExecutionOptionsWithParameters;
|
|
130
|
+
"chat-completion": AgentExecutionOptionsWithParameters & {
|
|
131
|
+
/** The single message content for the chat completion */
|
|
132
|
+
message: string;
|
|
133
|
+
/** Optional array of message objects representing the conversation history */
|
|
134
|
+
messages?: {
|
|
135
|
+
role: string;
|
|
136
|
+
content: string;
|
|
137
|
+
}[];
|
|
138
|
+
};
|
|
139
|
+
"proxy": AgentExecutionOptions & ProxyExecutionOptions;
|
|
140
|
+
};
|
|
141
|
+
type AgentResult = {
|
|
142
|
+
content: string;
|
|
143
|
+
instance_id: string;
|
|
144
|
+
json_content?: any;
|
|
145
|
+
meta_analysis?: MetaAnalysisRes;
|
|
146
|
+
completion_usage?: CompletionUsageRes;
|
|
147
|
+
time_to_first_token?: number;
|
|
148
|
+
executor_task_logs?: ExecutorTaskLogsRes;
|
|
149
|
+
action_results?: {
|
|
150
|
+
[key: string]: PluginExecutionResult;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Represents the events that can occur during a realtime session.
|
|
155
|
+
*
|
|
156
|
+
* @remarks
|
|
157
|
+
* The SSEStreamEvents type defines all possible events that can be emitted during
|
|
158
|
+
* a Server-Sent Events (SSE) streaming session. These events help track the lifecycle
|
|
159
|
+
* of a streaming response, from initiation to completion, including error handling
|
|
160
|
+
* and data chunk processing.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const eventHandler = {
|
|
165
|
+
* start: () => console.log('Stream started'),
|
|
166
|
+
* content: (chunk) => console.log('Received chunk:', chunk),
|
|
167
|
+
* error: (error) => console.error('Stream error:', error?.message),
|
|
168
|
+
* stop: (message) => console.log('Stream completed:', message)
|
|
169
|
+
* };
|
|
170
|
+
*
|
|
171
|
+
* // Using with a stream
|
|
172
|
+
* stream.on('start', eventHandler.start);
|
|
173
|
+
* stream.on('content', eventHandler.content);
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
type SSEStreamEvents = {
|
|
177
|
+
/**
|
|
178
|
+
* Event triggered when the server starts streaming a new response.
|
|
179
|
+
*/
|
|
180
|
+
start: () => void;
|
|
181
|
+
/**
|
|
182
|
+
* Event triggered when an error occurs.
|
|
183
|
+
* @param error - The error object. May contain a message.
|
|
184
|
+
*/
|
|
185
|
+
error: (error?: {
|
|
186
|
+
message?: string;
|
|
187
|
+
}) => void;
|
|
188
|
+
/**
|
|
189
|
+
* Event triggered when there is a new chunk of data available.
|
|
190
|
+
* @param data - The data chunk.
|
|
191
|
+
*/
|
|
192
|
+
content: (data: string) => void;
|
|
193
|
+
/**
|
|
194
|
+
* Event triggered when the server stops streaming a response.
|
|
195
|
+
* @param message - The final message object.
|
|
196
|
+
* @param message.sender - The sender of the message, either "user" or "bot".
|
|
197
|
+
* @param message.createdAt - The date when the message was created.
|
|
198
|
+
* @param message.type - The type of the message, e.g., "text", "image", or "error".
|
|
199
|
+
* @param message.value - The content of the message.
|
|
200
|
+
* @param message.meta_analysis - Optional meta-analysis results.
|
|
201
|
+
* @param message.completion_usage - Optional completion usage information.
|
|
202
|
+
* @param message.time_to_first_token - Optional time to first token.
|
|
203
|
+
* @param message.executor_task_logs - Optional executor task logs.
|
|
204
|
+
* @param message.attachedVolatileKnowledges - Optional attached volatile knowledges.
|
|
205
|
+
* @param message.action_results - Optional action results.
|
|
206
|
+
*/
|
|
207
|
+
stop: (message: AgentResult) => void;
|
|
208
|
+
};
|
|
209
|
+
type ExecuteBodyParams = Array<{
|
|
210
|
+
Key: string;
|
|
211
|
+
Value: any;
|
|
212
|
+
}>;
|
|
213
|
+
type MetaAnalysisRes = {
|
|
214
|
+
[key: string]: any;
|
|
215
|
+
} & {
|
|
216
|
+
policy_compliance?: {
|
|
217
|
+
compliance_score?: number;
|
|
218
|
+
explanation?: string;
|
|
219
|
+
policy_violations?: {
|
|
220
|
+
source_id?: string;
|
|
221
|
+
source_document_name: string;
|
|
222
|
+
chunk_id?: string;
|
|
223
|
+
section_number?: string;
|
|
224
|
+
section?: string;
|
|
225
|
+
policy?: string;
|
|
226
|
+
policy_name: string;
|
|
227
|
+
policy_id?: string;
|
|
228
|
+
}[];
|
|
229
|
+
};
|
|
230
|
+
pii_release_risk?: {
|
|
231
|
+
risk_score?: number;
|
|
232
|
+
explanation?: string;
|
|
233
|
+
};
|
|
234
|
+
ethics?: {
|
|
235
|
+
score?: number;
|
|
236
|
+
explanation?: string;
|
|
237
|
+
avoid_topics?: {
|
|
238
|
+
topic: string;
|
|
239
|
+
reason: string;
|
|
240
|
+
}[];
|
|
241
|
+
};
|
|
242
|
+
deception_estimation?: {
|
|
243
|
+
deception_score?: number;
|
|
244
|
+
explanation?: string;
|
|
245
|
+
};
|
|
246
|
+
cybersecurity_threat?: {
|
|
247
|
+
threat_assessment?: number;
|
|
248
|
+
explanation?: string;
|
|
249
|
+
};
|
|
250
|
+
social_content_risk?: {
|
|
251
|
+
risk_score?: number;
|
|
252
|
+
explanation?: string;
|
|
253
|
+
};
|
|
254
|
+
conversation_analysis?: {
|
|
255
|
+
emotion_value_estimate?: number;
|
|
256
|
+
predicted_next_goal?: string;
|
|
257
|
+
attended_to_features?: string[];
|
|
258
|
+
topic_area?: string;
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
type CompletionUsageRes = {
|
|
262
|
+
completion_tokens: number;
|
|
263
|
+
prompt_tokens: number;
|
|
264
|
+
total_tokens: number;
|
|
265
|
+
};
|
|
266
|
+
type ExecutorTaskLogsRes = {
|
|
267
|
+
description: string;
|
|
268
|
+
duration: number;
|
|
269
|
+
}[];
|
|
270
|
+
type SpeechGenerationResult = {
|
|
271
|
+
content: string;
|
|
272
|
+
finish_reason?: string;
|
|
273
|
+
usage?: {
|
|
274
|
+
[key: string]: any;
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
type PluginExecutionResult = SpeechGenerationResult;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Events that can be emitted by a realtime session.
|
|
281
|
+
*
|
|
282
|
+
* @remarks
|
|
283
|
+
* The RealtimeSessionEvents type defines all possible events that can be triggered during
|
|
284
|
+
* a realtime conversation session with Serenity. These events help track the lifecycle
|
|
285
|
+
* and state of the session, from creation to completion, including speech interactions
|
|
286
|
+
* and error handling.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* session.on('session.created', () => {
|
|
291
|
+
* console.log('Session started');
|
|
292
|
+
* });
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
type RealtimeSessionEvents = {
|
|
296
|
+
/**
|
|
297
|
+
* Triggered when a new session is initialized
|
|
298
|
+
*/
|
|
299
|
+
"session.created": () => void;
|
|
300
|
+
/**
|
|
301
|
+
* Triggered when voice input begins
|
|
302
|
+
*/
|
|
303
|
+
"speech.started": () => void;
|
|
304
|
+
/**
|
|
305
|
+
* Triggered when voice input ends
|
|
306
|
+
*/
|
|
307
|
+
"speech.stopped": () => void;
|
|
308
|
+
/**
|
|
309
|
+
* Triggered when the agent has completed generating a response
|
|
310
|
+
*/
|
|
311
|
+
"response.done": () => void;
|
|
312
|
+
/**
|
|
313
|
+
* Triggered when any error occurs during the session
|
|
314
|
+
* @param message - Optional error message
|
|
315
|
+
*/
|
|
316
|
+
error: (message?: string) => void;
|
|
317
|
+
/**
|
|
318
|
+
* Triggered when the session is terminated
|
|
319
|
+
* @param reason - Optional termination reason
|
|
320
|
+
* @param details - Optional additional details
|
|
321
|
+
*/
|
|
322
|
+
"session.stopped": (reason?: string, details?: any) => void;
|
|
323
|
+
/**
|
|
324
|
+
* Triggered when Serenity processes a response
|
|
325
|
+
* @param data - The complete response object containing:
|
|
326
|
+
* - content: The main text content of the response
|
|
327
|
+
* - instance_id: Unique identifier for the response instance
|
|
328
|
+
* - json_content?: Optional structured data in JSON format
|
|
329
|
+
* - meta_analysis?: Optional metadata analysis results
|
|
330
|
+
* - completion_usage?: Optional usage metrics for the completion
|
|
331
|
+
* - time_to_first_token?: Optional time taken to receive first token
|
|
332
|
+
* - executor_task_logs?: Optional logs from task execution
|
|
333
|
+
* - action_results?: Optional results from plugin executions
|
|
334
|
+
*/
|
|
335
|
+
"response.processed": (data: AgentResult) => void;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
declare class RealtimeSession extends EventEmitter<RealtimeSessionEvents> {
|
|
339
|
+
#private;
|
|
340
|
+
private agentCode;
|
|
341
|
+
private apiKey;
|
|
342
|
+
private baseUrl;
|
|
343
|
+
private inputParameters?;
|
|
344
|
+
private userIdentifier?;
|
|
345
|
+
private agentVersion?;
|
|
346
|
+
private channel?;
|
|
347
|
+
private inactivityTimeout?;
|
|
348
|
+
private timeout;
|
|
349
|
+
private sessionConfiguration?;
|
|
350
|
+
private peerConnection?;
|
|
351
|
+
private localStream?;
|
|
352
|
+
private dataChannel?;
|
|
353
|
+
private socket?;
|
|
354
|
+
constructor(agentCode: string, apiKey: string, baseUrl: string, options?: AgentExecutionOptionsWithParameters);
|
|
355
|
+
/**
|
|
356
|
+
* Starts the real-time session.
|
|
357
|
+
*/
|
|
358
|
+
start(): Promise<void>;
|
|
359
|
+
/**
|
|
360
|
+
* Stops the real-time session.
|
|
361
|
+
*/
|
|
362
|
+
stop(): void;
|
|
363
|
+
/**
|
|
364
|
+
* Allows the user to mute the microphone during a real-time voice session.
|
|
365
|
+
*/
|
|
366
|
+
muteMicrophone(): void;
|
|
367
|
+
/**
|
|
368
|
+
* Allows the user to unmute the microphone during a real-time voice session.
|
|
369
|
+
*/
|
|
370
|
+
unmuteMicrophone(): void;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
type MessageOptions = {
|
|
374
|
+
inputParameters?: {
|
|
375
|
+
[key: string]: any;
|
|
376
|
+
};
|
|
377
|
+
volatileKnowledgeIds?: string[];
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
declare class Conversation extends EventEmitter<SSEStreamEvents> {
|
|
381
|
+
#private;
|
|
382
|
+
private agentCode;
|
|
383
|
+
private apiKey;
|
|
384
|
+
private baseUrl;
|
|
385
|
+
private inputParameters?;
|
|
386
|
+
private userIdentifier?;
|
|
387
|
+
private agentVersion?;
|
|
388
|
+
private channel?;
|
|
389
|
+
conversationId?: string;
|
|
390
|
+
private constructor();
|
|
391
|
+
private static create;
|
|
392
|
+
streamMessage(message: string, options?: MessageOptions): Promise<AgentResult>;
|
|
393
|
+
sendMessage(message: string, options?: MessageOptions): Promise<AgentResult>;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
declare abstract class SystemAgent<T extends keyof SystemAgentExecutionOptionsMap> extends EventEmitter<SSEStreamEvents> {
|
|
397
|
+
protected readonly agentCode: string;
|
|
398
|
+
protected readonly apiKey: string;
|
|
399
|
+
protected readonly baseUrl: string;
|
|
400
|
+
protected readonly options?: SystemAgentExecutionOptionsMap[T] | undefined;
|
|
401
|
+
protected constructor(agentCode: string, apiKey: string, baseUrl: string, options?: SystemAgentExecutionOptionsMap[T] | undefined);
|
|
402
|
+
stream(): Promise<AgentResult>;
|
|
403
|
+
protected execute(): Promise<AgentResult>;
|
|
404
|
+
protected createExecuteBody(stream: boolean): ExecuteBodyParams | {
|
|
405
|
+
[key: string]: any;
|
|
406
|
+
};
|
|
407
|
+
protected appendUserIdentifierIfNeeded(body: ExecuteBodyParams): void;
|
|
408
|
+
protected appendVolatileKnowledgeIdsIfNeeded(body: ExecuteBodyParams): void;
|
|
409
|
+
protected appendChannelIfNeeded(body: ExecuteBodyParams): void;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
declare class Activity extends SystemAgent<"activity"> {
|
|
413
|
+
private constructor();
|
|
414
|
+
static create(agentCode: string, apiKey: string, baseUrl: string, options?: SystemAgentExecutionOptionsMap["activity"]): Activity;
|
|
415
|
+
static createAndExecute(agentCode: string, apiKey: string, baseUrl: string, options?: SystemAgentExecutionOptionsMap["activity"]): Promise<AgentResult>;
|
|
416
|
+
protected createExecuteBody(stream: boolean): ExecuteBodyParams | {
|
|
417
|
+
[key: string]: any;
|
|
418
|
+
};
|
|
419
|
+
private appendInputParametersIfNeeded;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
declare class ChatCompletion extends SystemAgent<"chat-completion"> {
|
|
423
|
+
private constructor();
|
|
424
|
+
static create(agentCode: string, apiKey: string, baseUrl: string, options?: SystemAgentExecutionOptionsMap["chat-completion"]): ChatCompletion;
|
|
425
|
+
static createAndExecute(agentCode: string, apiKey: string, baseUrl: string, options?: SystemAgentExecutionOptionsMap["chat-completion"]): Promise<AgentResult>;
|
|
426
|
+
protected createExecuteBody(stream: boolean): ExecuteBodyParams | {
|
|
427
|
+
[key: string]: any;
|
|
428
|
+
};
|
|
429
|
+
private appendMessagesIfNeeded;
|
|
430
|
+
private appendMessageIfNeeded;
|
|
431
|
+
private appendInputParametersIfNeeded;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
declare class Plan extends SystemAgent<"plan"> {
|
|
435
|
+
private constructor();
|
|
436
|
+
static create(agentCode: string, apiKey: string, baseUrl: string, options?: SystemAgentExecutionOptionsMap["plan"]): Plan;
|
|
437
|
+
static createAndExecute(agentCode: string, apiKey: string, baseUrl: string, options?: SystemAgentExecutionOptionsMap["plan"]): Promise<AgentResult>;
|
|
438
|
+
protected createExecuteBody(stream: boolean): ExecuteBodyParams | {
|
|
439
|
+
[key: string]: any;
|
|
440
|
+
};
|
|
441
|
+
private appendInputParametersIfNeeded;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
declare class Proxy extends SystemAgent<"proxy"> {
|
|
445
|
+
private constructor();
|
|
446
|
+
static create(agentCode: string, apiKey: string, baseUrl: string, options?: SystemAgentExecutionOptionsMap["proxy"]): Proxy;
|
|
447
|
+
static createAndExecute(agentCode: string, apiKey: string, baseUrl: string, options?: SystemAgentExecutionOptionsMap["proxy"]): Promise<AgentResult>;
|
|
448
|
+
protected createExecuteBody(stream: boolean): ExecuteBodyParams | {
|
|
449
|
+
[key: string]: any;
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
type ConversationalAgentScope<T extends keyof ConversationalAgentExecutionOptionsMap> = {
|
|
454
|
+
/**
|
|
455
|
+
* Create a new conversation with an agent.
|
|
456
|
+
* This allows you to send messages and receive responses.
|
|
457
|
+
*
|
|
458
|
+
* ## Regular conversation example:
|
|
459
|
+
* ```typescript
|
|
460
|
+
* const conversation = await client.agents.assistants.createConversation("agent-code");
|
|
461
|
+
* const response = await conversation.sendMessage("Hello!");
|
|
462
|
+
* console.log(response.content);
|
|
463
|
+
* ```
|
|
464
|
+
*
|
|
465
|
+
* ## Streaming conversation example:
|
|
466
|
+
* ```typescript
|
|
467
|
+
* const conversation = await client.agents.assistants
|
|
468
|
+
* .createConversation("agent-code")
|
|
469
|
+
* .on("start", () => console.log("Started"))
|
|
470
|
+
* .on("content", (chunk) => console.log(chunk))
|
|
471
|
+
* .on("error", (error) => console.error(error));
|
|
472
|
+
*
|
|
473
|
+
* await conversation.streamMessage("Hello!");
|
|
474
|
+
* ```
|
|
475
|
+
*
|
|
476
|
+
* @param agentCode - The unique identifier of the agent
|
|
477
|
+
* @param options - Additional options for the conversation
|
|
478
|
+
* @returns A Promise that resolves to a Conversation instance
|
|
479
|
+
*/
|
|
480
|
+
createConversation: (agentCode: string, options?: ConversationalAgentExecutionOptionsMap[T]) => Promise<Conversation>;
|
|
481
|
+
/**
|
|
482
|
+
* Create a real-time session with an agent.
|
|
483
|
+
* This allows for voice interactions and real-time responses.
|
|
484
|
+
*
|
|
485
|
+
* ## Real-time session example:
|
|
486
|
+
* ```typescript
|
|
487
|
+
* const session = client.agents.assistants
|
|
488
|
+
* .createRealtimeSession("agent-code")
|
|
489
|
+
* .on("session.created", () => console.log("Session started"))
|
|
490
|
+
* .on("speech.started", () => console.log("User started talking"))
|
|
491
|
+
* .on("speech.stopped", () => console.log("User stopped talking"))
|
|
492
|
+
* .on("response.done", (response) => console.log("Response:", response))
|
|
493
|
+
* .on("session.stopped", () => console.log("Session stopped"));
|
|
494
|
+
*
|
|
495
|
+
* await session.start();
|
|
496
|
+
* // Later: session.stop();
|
|
497
|
+
* ```
|
|
498
|
+
*
|
|
499
|
+
* @param agentCode - The unique identifier of the agent
|
|
500
|
+
* @param options - Additional options for the real-time session
|
|
501
|
+
* @returns A RealtimeSession instance
|
|
502
|
+
*/
|
|
503
|
+
createRealtimeSession: (agentCode: string, options?: ConversationalAgentExecutionOptionsMap[T]) => RealtimeSession;
|
|
504
|
+
};
|
|
505
|
+
type SystemAgentScope<T extends keyof SystemAgentExecutionOptionsMap, TCreateReturn> = {
|
|
506
|
+
/**
|
|
507
|
+
* Execute an agent synchronously and get the result.
|
|
508
|
+
*
|
|
509
|
+
* ## Example:
|
|
510
|
+
* ```typescript
|
|
511
|
+
* const response = await client.agents.activities.execute("agent-code", {
|
|
512
|
+
* // Optional parameters specific to the agent type
|
|
513
|
+
* inputParameters: {
|
|
514
|
+
* param1: "value1",
|
|
515
|
+
* param2: "value2"
|
|
516
|
+
* }
|
|
517
|
+
* });
|
|
518
|
+
* console.log(response.content);
|
|
519
|
+
* ```
|
|
520
|
+
*
|
|
521
|
+
* @param agentCode - The unique identifier of the agent
|
|
522
|
+
* @param options - Additional options for the execution
|
|
523
|
+
* @returns A Promise that resolves to an AgentResult
|
|
524
|
+
*/
|
|
525
|
+
execute: (agentCode: string, options?: SystemAgentExecutionOptionsMap[T]) => Promise<AgentResult>;
|
|
526
|
+
/**
|
|
527
|
+
* Create an agent instance for streaming execution.
|
|
528
|
+
*
|
|
529
|
+
* ## Streaming example:
|
|
530
|
+
* ```typescript
|
|
531
|
+
* const agent = client.agents.activities
|
|
532
|
+
* .create("agent-code", {
|
|
533
|
+
* // Optional parameters specific to the agent
|
|
534
|
+
* inputParameters: {
|
|
535
|
+
* param1: "value1",
|
|
536
|
+
* param2: "value2"
|
|
537
|
+
* }
|
|
538
|
+
* })
|
|
539
|
+
* .on("start", () => console.log("Started"))
|
|
540
|
+
* .on("content", (chunk) => console.log(chunk))
|
|
541
|
+
* .on("error", (error) => console.error(error));
|
|
542
|
+
*
|
|
543
|
+
* await agent.stream();
|
|
544
|
+
* ```
|
|
545
|
+
*
|
|
546
|
+
* @param agentCode - The unique identifier of the agent
|
|
547
|
+
* @param options - Additional options for the agent creation
|
|
548
|
+
* @returns An agent instance ready for streaming
|
|
549
|
+
*/
|
|
550
|
+
create: (agentCode: string, options?: SystemAgentExecutionOptionsMap[T]) => TCreateReturn;
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
declare class SerenityClient {
|
|
554
|
+
private apiKey;
|
|
555
|
+
private baseUrl;
|
|
556
|
+
/**
|
|
557
|
+
* Interact with the different agents available in Serenity Star.
|
|
558
|
+
* You can choose between assistants, copilots, activities, chat completions, proxies, and plans.
|
|
559
|
+
*/
|
|
560
|
+
readonly agents: {
|
|
561
|
+
/**
|
|
562
|
+
* Interact with Assistant agents available in Serenity Star.
|
|
563
|
+
* This allows you to create conversations and real-time sessions.
|
|
564
|
+
*
|
|
565
|
+
* ## Start a new conversation and send a message:
|
|
566
|
+
* ```typescript
|
|
567
|
+
* // Regular text conversation
|
|
568
|
+
* const conversation = await client.agents.assistants.createConversation("translator-assistant");
|
|
569
|
+
* const response = await conversation.sendMessage("The sun was beginning to set...");
|
|
570
|
+
* console.log(response.content);
|
|
571
|
+
*
|
|
572
|
+
* ```
|
|
573
|
+
*
|
|
574
|
+
* ## Stream message with SSE
|
|
575
|
+
* ```typescript
|
|
576
|
+
* const conversation = await client.agents.assistants
|
|
577
|
+
* .createConversation("translator-assistant")
|
|
578
|
+
* .on("start", () => console.log("Started"))
|
|
579
|
+
* .on("content", (chunk) => console.log(chunk))
|
|
580
|
+
* .on("error", (error) => console.error(error));
|
|
581
|
+
*
|
|
582
|
+
* await conversation.streamMessage("The sun was beginning to set...");
|
|
583
|
+
*
|
|
584
|
+
* ```
|
|
585
|
+
*
|
|
586
|
+
* ## Real-time voice conversation example:
|
|
587
|
+
* ```typescript
|
|
588
|
+
* const session = client.agents.assistants.createRealtimeSession("marketing-assistant")
|
|
589
|
+
* .on("session.created", () => console.log("Session started"))
|
|
590
|
+
* .on("speech.started", () => console.log("User started talking"))
|
|
591
|
+
* .on("speech.stopped", () => console.log("User stopped talking"))
|
|
592
|
+
* .on("response.done", (response) => console.log("Response:", response))
|
|
593
|
+
* .on("session.stopped", () => console.log("Session stopped"));
|
|
594
|
+
*
|
|
595
|
+
* await session.start();
|
|
596
|
+
* // Later: session.stop();
|
|
597
|
+
* ```
|
|
598
|
+
*/
|
|
599
|
+
assistants: ConversationalAgentScope<"assistant">;
|
|
600
|
+
/**
|
|
601
|
+
* Interact with Copilot agents available in Serenity Star.
|
|
602
|
+
* Similar to assistants but allows you to interact with the UI through callbacks.
|
|
603
|
+
*
|
|
604
|
+
* Text conversation example:
|
|
605
|
+
* ```typescript
|
|
606
|
+
* // Regular conversation
|
|
607
|
+
* const conversation = await client.agents.copilots.createConversation("app-copilot");
|
|
608
|
+
* const response = await conversation.sendMessage("How do I create a new support ticket?");
|
|
609
|
+
* console.log(response.content);
|
|
610
|
+
*
|
|
611
|
+
* // Streaming conversation
|
|
612
|
+
* const conversation = await client.agents.copilots
|
|
613
|
+
* .createConversation("app-copilot")
|
|
614
|
+
* .on("start", () => console.log("Started"))
|
|
615
|
+
* .on("content", (chunk) => console.log(chunk))
|
|
616
|
+
* .on("error", (error) => console.error(error));
|
|
617
|
+
*
|
|
618
|
+
* await conversation.streamMessage("How do I create a new support ticket?");
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
copilots: ConversationalAgentScope<"copilot">;
|
|
622
|
+
/**
|
|
623
|
+
* Interact with Activity agents available in Serenity Star.
|
|
624
|
+
* This allows you to execute activities.
|
|
625
|
+
* It supports streaming.
|
|
626
|
+
* Execute simple tasks based on the user input.
|
|
627
|
+
*
|
|
628
|
+
* ## Regular activity execution:
|
|
629
|
+
* ```typescript
|
|
630
|
+
* const response = await client.agents.activities.execute("marketing-campaign")
|
|
631
|
+
* console.log(response.content);
|
|
632
|
+
*
|
|
633
|
+
* // With parameters
|
|
634
|
+
* const response = await client.agents.activities.execute("cooking-activity", {
|
|
635
|
+
* inputParameters: {
|
|
636
|
+
* ingredientOne: "chicken",
|
|
637
|
+
* ingredientTwo: "onion",
|
|
638
|
+
* ingredientThree: "cream",
|
|
639
|
+
* }
|
|
640
|
+
* });
|
|
641
|
+
* ```
|
|
642
|
+
*
|
|
643
|
+
* ## Stream activity with SSE:
|
|
644
|
+
* ```typescript
|
|
645
|
+
* const activity = client.agents.activities
|
|
646
|
+
* .create("marketing-campaign")
|
|
647
|
+
* .on("start", () => console.log("Started"))
|
|
648
|
+
* .on("content", (chunk) => console.log(chunk))
|
|
649
|
+
* .on("error", (error) => console.error(error));
|
|
650
|
+
*
|
|
651
|
+
* await activity.stream();
|
|
652
|
+
* ```
|
|
653
|
+
*/
|
|
654
|
+
activities: SystemAgentScope<"activity", Activity>;
|
|
655
|
+
/**
|
|
656
|
+
* Interact with Chat Completion agents available in Serenity Star.
|
|
657
|
+
* This allows you to execute chat completions.
|
|
658
|
+
* It supports streaming.
|
|
659
|
+
* Chat completions allows you to fully control the conversation and generate completions.
|
|
660
|
+
*
|
|
661
|
+
* ## Regular chat completion:
|
|
662
|
+
* ```typescript
|
|
663
|
+
* const response = await client.agents.chatCompletions.execute("Health-Coach", {
|
|
664
|
+
* message: "Hello!"
|
|
665
|
+
* });
|
|
666
|
+
* console.log(response.content);
|
|
667
|
+
* ```
|
|
668
|
+
*
|
|
669
|
+
* ## Stream chat completion with SSE:
|
|
670
|
+
* ```typescript
|
|
671
|
+
* const chatCompletion = client.agents.chatCompletions
|
|
672
|
+
* .create("Health-Coach", {
|
|
673
|
+
* message: "Hello!"
|
|
674
|
+
* })
|
|
675
|
+
* .on("start", () => console.log("Started"))
|
|
676
|
+
* .on("content", (chunk) => console.log(chunk))
|
|
677
|
+
* .on("error", (error) => console.error(error));
|
|
678
|
+
*
|
|
679
|
+
* await chatCompletion.stream();
|
|
680
|
+
* ```
|
|
681
|
+
*/
|
|
682
|
+
chatCompletions: SystemAgentScope<"chat-completion", ChatCompletion>;
|
|
683
|
+
/**
|
|
684
|
+
* Interact with Proxy agents available in Serenity Star.
|
|
685
|
+
* This allows you to execute proxies.
|
|
686
|
+
* It supports streaming.
|
|
687
|
+
* Proxy agents allows you to define a set of parameters dynamically for each request
|
|
688
|
+
*
|
|
689
|
+
* ## Regular proxy execution:
|
|
690
|
+
* ```typescript
|
|
691
|
+
* const response = await client.agents.proxies.execute("proxy-agent", {
|
|
692
|
+
* model: "gpt-4o-mini-2024-07-18",
|
|
693
|
+
* messages: [
|
|
694
|
+
* {
|
|
695
|
+
* role: "system",
|
|
696
|
+
* content: "You are a helpful assistant. Always use short and concise responses"
|
|
697
|
+
* },
|
|
698
|
+
* { role: "user", content: "What is artificial intelligence?" }
|
|
699
|
+
* ],
|
|
700
|
+
* temperature: 1,
|
|
701
|
+
* max_tokens: 250
|
|
702
|
+
* });
|
|
703
|
+
* console.log(response.content);
|
|
704
|
+
* ```
|
|
705
|
+
*
|
|
706
|
+
* ## Stream proxy with SSE:
|
|
707
|
+
* ```typescript
|
|
708
|
+
* const proxy = client.agents.proxies
|
|
709
|
+
* .create("proxy-agent", {
|
|
710
|
+
* model: "gpt-4o-mini-2024-07-18",
|
|
711
|
+
* messages: [
|
|
712
|
+
* {
|
|
713
|
+
* role: "system",
|
|
714
|
+
* content: "You are a helpful assistant. Always use short and concise responses"
|
|
715
|
+
* },
|
|
716
|
+
* { role: "user", content: "What is artificial intelligence?" }
|
|
717
|
+
* ],
|
|
718
|
+
* temperature: 1,
|
|
719
|
+
* max_tokens: 250
|
|
720
|
+
* })
|
|
721
|
+
* .on("start", () => console.log("Started"))
|
|
722
|
+
* .on("content", (chunk) => console.log(chunk))
|
|
723
|
+
* .on("error", (error) => console.error(error));
|
|
724
|
+
*
|
|
725
|
+
* await proxy.stream();
|
|
726
|
+
* ```
|
|
727
|
+
*/
|
|
728
|
+
proxies: SystemAgentScope<"proxy", Proxy>;
|
|
729
|
+
/**
|
|
730
|
+
* Interact with Plan agents available in Serenity Star.
|
|
731
|
+
* This allows you to execute plans.
|
|
732
|
+
* It supports streaming.
|
|
733
|
+
* Plan agents are capable of building an execution plan based on the user input and execute it.
|
|
734
|
+
*
|
|
735
|
+
* ## Regular plan execution:
|
|
736
|
+
* ```typescript
|
|
737
|
+
* const response = await client.agents.plans.execute("event-planner");
|
|
738
|
+
* console.log(response.content);
|
|
739
|
+
* ```
|
|
740
|
+
*
|
|
741
|
+
* ## Stream plan with SSE:
|
|
742
|
+
* ```typescript
|
|
743
|
+
* const plan = client.agents.plans
|
|
744
|
+
* .create("event-planner")
|
|
745
|
+
* .on("start", () => console.log("Started"))
|
|
746
|
+
* .on("content", (chunk) => console.log(chunk))
|
|
747
|
+
* .on("error", (error) => console.error(error));
|
|
748
|
+
*
|
|
749
|
+
* await plan.stream();
|
|
750
|
+
* ```
|
|
751
|
+
*/
|
|
752
|
+
plans: SystemAgentScope<"plan", Plan>;
|
|
753
|
+
};
|
|
754
|
+
constructor(options: SerenityClientOptions);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
export { RealtimeSession, SerenityClient };
|