@serenity-star/sdk 1.0.3 → 2.1.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 +390 -85
- package/dist/index.d.ts +390 -85
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/readme.md +134 -75
package/readme.md
CHANGED
|
@@ -11,6 +11,7 @@ The Serenity Star JS/TS SDK provides a comprehensive interface for interacting w
|
|
|
11
11
|
- [Usage](#usage)
|
|
12
12
|
- [Assistants / Copilots](#assistants--copilots)
|
|
13
13
|
- [Start a new conversation with an Agent](#start-a-new-conversation-with-an-agent)
|
|
14
|
+
- [Get conversation information](#get-conversation-information)
|
|
14
15
|
- [Sending messages within a conversation](#sending-messages-within-a-conversation)
|
|
15
16
|
- [Stream message with SSE](#stream-message-with-sse)
|
|
16
17
|
- [Real time conversation](#real-time-conversation)
|
|
@@ -24,9 +25,6 @@ The Serenity Star JS/TS SDK provides a comprehensive interface for interacting w
|
|
|
24
25
|
- [Chat Completions](#chat-completions)
|
|
25
26
|
- [Execute a chat completion](#execute-a-chat-completion)
|
|
26
27
|
- [Stream responses with SSE](#stream-responses-with-sse-2)
|
|
27
|
-
- [Plans](#plans)
|
|
28
|
-
- [Execute a plan](#execute-a-plan)
|
|
29
|
-
- [Stream responses with SSE](#stream-responses-with-sse-3)
|
|
30
28
|
|
|
31
29
|
# Installation
|
|
32
30
|
|
|
@@ -60,10 +58,79 @@ const client = new SerenityClient({
|
|
|
60
58
|
apiKey: '<SERENITY_API_KEY>',
|
|
61
59
|
});
|
|
62
60
|
|
|
63
|
-
// Create conversation with an assistant
|
|
61
|
+
// Create a new conversation with an assistant
|
|
64
62
|
const conversation = await client.agents.assistants.createConversation("chef-assistant");
|
|
65
63
|
```
|
|
66
64
|
|
|
65
|
+
## Get conversation information
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
import SerenityClient from '@serenity-star/sdk';
|
|
69
|
+
|
|
70
|
+
const client = new SerenityClient({
|
|
71
|
+
apiKey: '<SERENITY_API_KEY>',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Get information about an assistant agent conversation (basic example)
|
|
75
|
+
const agentInfo = await client.agents.assistants.getInfoByCode("chef-assistant");
|
|
76
|
+
|
|
77
|
+
console.log(
|
|
78
|
+
agentInfo.conversation.initialMessage, // "Hello! I'm your personal chef assistant..."
|
|
79
|
+
agentInfo.conversation.starters, // ["What's for dinner tonight?", "Help me plan a meal", ...]
|
|
80
|
+
agentInfo.agent.version, // 1
|
|
81
|
+
agentInfo.agent.visionEnabled, // true/false
|
|
82
|
+
agentInfo.agent.isRealtime, // true/false
|
|
83
|
+
agentInfo.channel, // Optional chat widget configuration
|
|
84
|
+
agentInfo.agent.imageId // Agent's profile image ID
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
// Get information about an assistant agent conversation (advanced example with options)
|
|
88
|
+
const agentInfoAdvanced = await client.agents.assistants.getInfoByCode("chef-assistant", {
|
|
89
|
+
agentVersion: 2, // Target specific version of the agent
|
|
90
|
+
inputParameters: {
|
|
91
|
+
dietaryRestrictions: "vegetarian",
|
|
92
|
+
cuisinePreference: "italian",
|
|
93
|
+
skillLevel: "beginner"
|
|
94
|
+
},
|
|
95
|
+
userIdentifier: "user-123",
|
|
96
|
+
channel: "web"
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
console.log(
|
|
100
|
+
agentInfoAdvanced.conversation.initialMessage, // "Hello! I'm your personalized Italian vegetarian chef assistant for beginners..."
|
|
101
|
+
agentInfoAdvanced.conversation.starters, // ["Show me easy vegetarian pasta recipes", "What Italian herbs should I use?", ...]
|
|
102
|
+
agentInfoAdvanced.agent.version, // 2
|
|
103
|
+
);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Get conversation by id
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import SerenityClient from '@serenity-star/sdk';
|
|
110
|
+
|
|
111
|
+
const client = new SerenityClient({
|
|
112
|
+
apiKey: '<SERENITY_API_KEY>',
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Get conversation by id (basic example)
|
|
116
|
+
const conversation = await client.agents.assistants.getConversationById("<agent-code>", "<conversation-id>");
|
|
117
|
+
|
|
118
|
+
console.log(
|
|
119
|
+
conversation.id, // "<conversation-id>"
|
|
120
|
+
conversation.messages, // Array of messages
|
|
121
|
+
conversation.open // Boolean that indicates if the conversation was closed or not
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// Get conversation by id with executor task logs
|
|
125
|
+
const conversationWithLogs = await client.agents.assistants.getConversationById("<agent-code>", "<conversation-id>", {
|
|
126
|
+
showExecutorTaskLogs: true
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
console.log(
|
|
130
|
+
conversationWithLogs.executorTaskLogs // Detailed task execution logs
|
|
131
|
+
);
|
|
132
|
+
```
|
|
133
|
+
|
|
67
134
|
## Sending messages within a conversation
|
|
68
135
|
|
|
69
136
|
```tsx
|
|
@@ -83,6 +150,7 @@ console.log(
|
|
|
83
150
|
response.content, // "Sure! Here is a recipe for parmesan chicken..."
|
|
84
151
|
response.completion_usage, // { completion_tokens: 200, prompt_tokens: 30, total_tokens: 230 }
|
|
85
152
|
response.executor_task_logs, // [ { description: 'Task 1', duration: 100 }, { description: 'Task 2', duration: 500 }]
|
|
153
|
+
response.instance_id, // instance id for the conversation
|
|
86
154
|
)
|
|
87
155
|
```
|
|
88
156
|
|
|
@@ -113,7 +181,8 @@ const response = await conversation.streamMessage("I would like to get a recipe
|
|
|
113
181
|
console.log(
|
|
114
182
|
response.content, // "Sure! Here is a recipe for parmesan chicken..."
|
|
115
183
|
response.completion_usage, // { completion_tokens: 200, prompt_tokens: 30, total_tokens: 230 }
|
|
116
|
-
response.executor_task_logs, // [ { description: 'Task 1', duration: 100 }, { description: 'Task 2', duration: 500 }]
|
|
184
|
+
response.executor_task_logs, // [ { description: 'Task 1', duration: 100 }, { description: 'Task 2', duration: 500 }],
|
|
185
|
+
response.instance_id, // instance id for the conversation
|
|
117
186
|
)
|
|
118
187
|
```
|
|
119
188
|
|
|
@@ -126,7 +195,7 @@ const client = new SerenityClient({
|
|
|
126
195
|
apiKey: '<SERENITY_API_KEY>',
|
|
127
196
|
});
|
|
128
197
|
|
|
129
|
-
// Create
|
|
198
|
+
// Create a real-time session
|
|
130
199
|
const session = await client.agents.assistants.createRealtimeSession("chef-assistant")
|
|
131
200
|
.on("session.created", () => {
|
|
132
201
|
// Update UI to provide feedback if you need
|
|
@@ -157,6 +226,65 @@ session.unmuteMicrophone()
|
|
|
157
226
|
session.stop();
|
|
158
227
|
```
|
|
159
228
|
|
|
229
|
+
## Message Feedback
|
|
230
|
+
|
|
231
|
+
You can collect user feedback on agent responses to help improve the quality of your assistant.
|
|
232
|
+
|
|
233
|
+
### Submit feedback
|
|
234
|
+
|
|
235
|
+
```tsx
|
|
236
|
+
import SerenityClient from '@serenity-star/sdk';
|
|
237
|
+
|
|
238
|
+
const client = new SerenityClient({
|
|
239
|
+
apiKey: '<SERENITY_API_KEY>',
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// Create conversation with an assistant
|
|
243
|
+
const conversation = await client.agents.assistants.createConversation("chef-assistant");
|
|
244
|
+
|
|
245
|
+
// Send a message
|
|
246
|
+
const response = await conversation.sendMessage("I would like to get a recipe for parmesan chicken");
|
|
247
|
+
|
|
248
|
+
// Submit positive feedback (thumbs up)
|
|
249
|
+
await conversation.submitFeedback({
|
|
250
|
+
agentMessageId: response.agent_message_id!,
|
|
251
|
+
feedback: true
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// Or submit negative feedback (thumbs down)
|
|
255
|
+
await conversation.submitFeedback({
|
|
256
|
+
agentMessageId: response.agent_message_id!,
|
|
257
|
+
feedback: false
|
|
258
|
+
});
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Remove feedback
|
|
262
|
+
|
|
263
|
+
```tsx
|
|
264
|
+
import SerenityClient from '@serenity-star/sdk';
|
|
265
|
+
|
|
266
|
+
const client = new SerenityClient({
|
|
267
|
+
apiKey: '<SERENITY_API_KEY>',
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
// Create conversation with an assistant
|
|
271
|
+
const conversation = await client.agents.assistants.createConversation("chef-assistant");
|
|
272
|
+
|
|
273
|
+
// Send a message
|
|
274
|
+
const response = await conversation.sendMessage("I would like to get a recipe for parmesan chicken");
|
|
275
|
+
|
|
276
|
+
// Submit feedback first
|
|
277
|
+
await conversation.submitFeedback({
|
|
278
|
+
agentMessageId: response.agent_message_id!,
|
|
279
|
+
feedback: true
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// Remove the feedback if the user changes their mind
|
|
283
|
+
await conversation.removeFeedback({
|
|
284
|
+
agentMessageId: response.agent_message_id!
|
|
285
|
+
});
|
|
286
|
+
```
|
|
287
|
+
|
|
160
288
|
---
|
|
161
289
|
|
|
162
290
|
# Activities
|
|
@@ -401,73 +529,4 @@ console.log(
|
|
|
401
529
|
response.content, // AI-generated response
|
|
402
530
|
response.completion_usage // { completion_tokens: 200, prompt_tokens: 30, total_tokens: 230 }
|
|
403
531
|
);
|
|
404
|
-
```
|
|
405
|
-
|
|
406
|
-
---
|
|
407
|
-
|
|
408
|
-
# Plans
|
|
409
|
-
|
|
410
|
-
## Execute a plan
|
|
411
|
-
|
|
412
|
-
```tsx
|
|
413
|
-
import SerenityClient from '@serenity-star/sdk';
|
|
414
|
-
|
|
415
|
-
const client = new SerenityClient({
|
|
416
|
-
apiKey: '<SERENITY_API_KEY>',
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
// Execute plan (basic example)
|
|
420
|
-
const response = await client.agents.plans.execute("event-planner");
|
|
421
|
-
|
|
422
|
-
// Execute plan (advanced example)
|
|
423
|
-
const response = await client.agents.plans.execute("event-planner", {
|
|
424
|
-
userIdentifier: "user-123",
|
|
425
|
-
agentVersion: 2,
|
|
426
|
-
channel: "web",
|
|
427
|
-
volatileKnowledgeIds: ["knowledge-1", "knowledge-2"]
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
console.log(
|
|
431
|
-
response.content,
|
|
432
|
-
response.completion_usage, // { completion_tokens: 200, prompt_tokens: 30, total_tokens: 230 }
|
|
433
|
-
response.executor_task_logs // [ { description: 'Task 1', duration: 100 }, { description: 'Task 2', duration: 500 }]
|
|
434
|
-
);
|
|
435
|
-
|
|
436
|
-
```
|
|
437
|
-
|
|
438
|
-
## Stream responses with SSE
|
|
439
|
-
|
|
440
|
-
```tsx
|
|
441
|
-
import SerenityClient from '@serenity-star/sdk';
|
|
442
|
-
|
|
443
|
-
const client = new SerenityClient({
|
|
444
|
-
apiKey: '<SERENITY_API_KEY>',
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
// Execute plan and stream response with Server Sent Events (SSE)
|
|
448
|
-
const plan = client.agents.plans.create("event-planner", {
|
|
449
|
-
userIdentifier: "user-123",
|
|
450
|
-
agentVersion: 2,
|
|
451
|
-
channel: "web",
|
|
452
|
-
volatileKnowledgeIds: ["knowledge-1", "knowledge-2"]
|
|
453
|
-
})
|
|
454
|
-
.on("start", () => {
|
|
455
|
-
console.log("Plan execution started");
|
|
456
|
-
})
|
|
457
|
-
.on("content", (chunk) => {
|
|
458
|
-
console.log("Response chunk:", chunk);
|
|
459
|
-
})
|
|
460
|
-
.on("error", (error) => {
|
|
461
|
-
console.error("Error:", error);
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
const response = await plan.stream();
|
|
465
|
-
|
|
466
|
-
// Access final response data
|
|
467
|
-
console.log(
|
|
468
|
-
response.content,
|
|
469
|
-
response.completion_usage, // { completion_tokens: 200, prompt_tokens: 30, total_tokens: 230 }
|
|
470
|
-
response.executor_task_logs // [ { description: 'Task 1', duration: 100 }, { description: 'Task 2', duration: 500 }]
|
|
471
|
-
);
|
|
472
|
-
|
|
473
532
|
```
|