@serenity-star/sdk 2.8.0 → 2.9.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 +76 -3
- package/dist/index.d.ts +76 -3
- 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 +71 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serenity-star/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"description": "The Serenity Star JavaScript SDK provides a convenient way to interact with the Serenity Star API, enabling you to build custom applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
package/readme.md
CHANGED
|
@@ -25,6 +25,8 @@ The Serenity Star JS/TS SDK provides a comprehensive interface for interacting w
|
|
|
25
25
|
- [Submit feedback](#submit-feedback)
|
|
26
26
|
- [Remove feedback](#remove-feedback)
|
|
27
27
|
- [Connector Status](#connector-status)
|
|
28
|
+
- [Tool approvals](#tool-approvals)
|
|
29
|
+
- [User choices](#user-choices)
|
|
28
30
|
- [Activities](#activities)
|
|
29
31
|
- [Execute an activity](#execute-an-activity)
|
|
30
32
|
- [Stream responses with SSE](#stream-responses-with-sse)
|
|
@@ -533,6 +535,75 @@ Notes:
|
|
|
533
535
|
finishes, so an approval raised on the very first turn is resolvable.
|
|
534
536
|
- A resumed turn can itself raise another approval; keep handling `pending_actions` until it is empty.
|
|
535
537
|
|
|
538
|
+
## User choices
|
|
539
|
+
|
|
540
|
+
When the agent needs input before it can continue, it stops and asks. The result carries a
|
|
541
|
+
`user_choice` pending action holding one or more questions, each with the options the agent
|
|
542
|
+
proposes.
|
|
543
|
+
|
|
544
|
+
Detect it on the result (or on the `stop` payload when streaming) and answer with
|
|
545
|
+
`streamUserChoices` / `sendUserChoices`. The resume turn carries **no user message** — the answers
|
|
546
|
+
are the whole turn — and continues the same conversation, so the answer arrives as the rest of the
|
|
547
|
+
same assistant response.
|
|
548
|
+
|
|
549
|
+
```tsx
|
|
550
|
+
import SerenityClient from '@serenity-star/sdk';
|
|
551
|
+
|
|
552
|
+
const client = new SerenityClient({
|
|
553
|
+
apiKey: '<SERENITY_API_KEY>',
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
const conversation = await client.agents.assistants.createConversation("chef-assistant");
|
|
557
|
+
|
|
558
|
+
const response = await conversation.streamMessage("Plan dinner for me tonight.");
|
|
559
|
+
|
|
560
|
+
const choice = response.pending_actions?.find((action) => action.type === "user_choice");
|
|
561
|
+
|
|
562
|
+
if (choice) {
|
|
563
|
+
for (const question of choice.questions) {
|
|
564
|
+
console.log(question.header); // "Cuisine" — short label, frequently absent
|
|
565
|
+
console.log(question.text); // "What kind of food are you in the mood for?"
|
|
566
|
+
console.log(question.is_multiselect) // false — pick one, or many when true
|
|
567
|
+
console.log(question.options); // [{ id, title, description? }, ...]
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// Ask the user, then echo each question id back with the option ids they picked.
|
|
571
|
+
const continuation = await conversation.streamUserChoices(
|
|
572
|
+
choice.questions.map((question) => ({
|
|
573
|
+
questionId: question.id,
|
|
574
|
+
selectedOptionIds: [question.options![0].id],
|
|
575
|
+
})),
|
|
576
|
+
);
|
|
577
|
+
|
|
578
|
+
console.log(continuation.content); // the rest of the answer
|
|
579
|
+
}
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
When none of the options fit, send the user's own words in `other` instead — with or without
|
|
583
|
+
selected options:
|
|
584
|
+
|
|
585
|
+
```tsx
|
|
586
|
+
await conversation.sendUserChoices([
|
|
587
|
+
{ questionId: question.id, selectedOptionIds: [], other: "Something vegetarian" },
|
|
588
|
+
]);
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
Notes:
|
|
592
|
+
|
|
593
|
+
- `questionId` must match a question's `id`, and every id in `selectedOptionIds` must match one of
|
|
594
|
+
that question's `options`. `header`, `text` and `description` are informational.
|
|
595
|
+
- Answer members are camelCase (`questionId`, `selectedOptionIds`, `other?`). `other` is optional,
|
|
596
|
+
trimmed, and omitted from the request when empty.
|
|
597
|
+
- Answer every question in the set. `selectedOptionIds` may be empty only when `other` carries the
|
|
598
|
+
answer instead.
|
|
599
|
+
- Unlike approvals, nothing is held server-side: the answers are folded into the text of the next
|
|
600
|
+
user message. An unanswered set never expires, so it can be answered on a later turn, and a plain
|
|
601
|
+
`sendMessage` / `streamMessage` also works if the user would rather just reply in their own words.
|
|
602
|
+
- User choices can only be answered on an existing conversation — both methods throw when
|
|
603
|
+
`conversation.conversationId` is not set yet. It is populated as soon as the first execution
|
|
604
|
+
finishes, so a question raised on the very first turn is answerable.
|
|
605
|
+
- A resumed turn can itself raise another question; keep handling `pending_actions` until it is empty.
|
|
606
|
+
|
|
536
607
|
---
|
|
537
608
|
|
|
538
609
|
# Activities
|