@serenity-star/sdk 2.6.7 → 2.8.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 +129 -3
- package/dist/index.d.ts +129 -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 +125 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serenity-star/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.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
|
@@ -39,6 +39,7 @@ The Serenity Star JS/TS SDK provides a comprehensive interface for interacting w
|
|
|
39
39
|
- [Download Attached Files](#download-attached-files)
|
|
40
40
|
- [Stop Streaming Response](#stop-streaming-response)
|
|
41
41
|
- [Reasoning (Chain-of-Thought)](#reasoning-chain-of-thought)
|
|
42
|
+
- [Task events](#task-events)
|
|
42
43
|
- [Citations](#citations)
|
|
43
44
|
- [Citations on stored messages](#citations-on-stored-messages)
|
|
44
45
|
- [Upload Files (Volatile Knowledge)](#upload-files-volatile-knowledge)
|
|
@@ -485,6 +486,53 @@ const newResponse = await conversation.sendMessage("I need a summary of my lates
|
|
|
485
486
|
console.log(newResponse.content); // Summary of the meeting notes
|
|
486
487
|
```
|
|
487
488
|
|
|
489
|
+
## Tool approvals
|
|
490
|
+
|
|
491
|
+
When a skill is configured as *Requires approval*, the run pauses instead of invoking it. The result
|
|
492
|
+
carries an `approval` pending action, and the conversation stays blocked until you send a decision:
|
|
493
|
+
any further message on it returns HTTP 400 with `errors["tool_approval_pending"]`.
|
|
494
|
+
|
|
495
|
+
Detect the request on the result (or on the `stop` payload when streaming) and resolve it with
|
|
496
|
+
`streamToolApprovals` / `sendToolApprovals`. The resume turn carries **no user message** — the
|
|
497
|
+
decision is the whole turn — and continues the same conversation, so the answer arrives as the rest
|
|
498
|
+
of the same assistant response.
|
|
499
|
+
|
|
500
|
+
```tsx
|
|
501
|
+
import SerenityClient from '@serenity-star/sdk';
|
|
502
|
+
|
|
503
|
+
const client = new SerenityClient({
|
|
504
|
+
apiKey: '<SERENITY_API_KEY>',
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
const conversation = await client.agents.assistants.createConversation("chef-assistant");
|
|
508
|
+
|
|
509
|
+
const response = await conversation.streamMessage("What are the trending recipes this week?");
|
|
510
|
+
|
|
511
|
+
const approval = response.pending_actions?.find((action) => action.type === "approval");
|
|
512
|
+
|
|
513
|
+
if (approval) {
|
|
514
|
+
console.log(approval.skill_code); // "web-search" — the skill awaiting approval
|
|
515
|
+
|
|
516
|
+
// Ask the user, then echo the request id back with their decision.
|
|
517
|
+
const continuation = await conversation.streamToolApprovals([
|
|
518
|
+
{ requestId: approval.request_id, approved: true },
|
|
519
|
+
]);
|
|
520
|
+
|
|
521
|
+
console.log(continuation.content); // the rest of the answer
|
|
522
|
+
}
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
Notes:
|
|
526
|
+
|
|
527
|
+
- `request_id` is the only value that must be echoed back. `call_id`, `skill_type`, `tool` and
|
|
528
|
+
`arguments` are informational.
|
|
529
|
+
- Decision members are camelCase (`requestId`, `approved`, `reason?`). `reason` is optional and
|
|
530
|
+
omitted from the request when empty.
|
|
531
|
+
- Approvals can only be resolved on an existing conversation — both methods throw when
|
|
532
|
+
`conversation.conversationId` is not set yet. It is populated as soon as the first execution
|
|
533
|
+
finishes, so an approval raised on the very first turn is resolvable.
|
|
534
|
+
- A resumed turn can itself raise another approval; keep handling `pending_actions` until it is empty.
|
|
535
|
+
|
|
488
536
|
---
|
|
489
537
|
|
|
490
538
|
# Activities
|
|
@@ -869,6 +917,83 @@ conversation
|
|
|
869
917
|
await conversation.streamMessage("Plan a three-course vegetarian dinner");
|
|
870
918
|
```
|
|
871
919
|
|
|
920
|
+
## Task events
|
|
921
|
+
|
|
922
|
+
While an agent streams, it reports the internal work it performs through the `task_start` / `task_stop` event pair. A **task** is any discrete step the agent runs on its way to an answer — a skill execution, a tool call, and whatever step types the platform adds later. The SDK forwards every task frame it receives without filtering, so new task types reach your handlers as soon as the platform starts emitting them.
|
|
923
|
+
|
|
924
|
+
Use them to reflect the agent's progress in your UI while it works, or to time, trace and log what the agent actually did.
|
|
925
|
+
|
|
926
|
+
These events only exist on **streamed** executions (`streamMessage` / `stream`). A non-streamed call returns the final result only.
|
|
927
|
+
|
|
928
|
+
Each task carries a `task_key` identifying what ran and a `metadata` object describing it. Both are task-type specific: match on `task_key` for the types you care about and ignore the rest, rather than assuming a single shape.
|
|
929
|
+
|
|
930
|
+
```tsx
|
|
931
|
+
import SerenityClient from '@serenity-star/sdk';
|
|
932
|
+
|
|
933
|
+
const client = new SerenityClient({
|
|
934
|
+
apiKey: '<SERENITY_API_KEY>',
|
|
935
|
+
});
|
|
936
|
+
|
|
937
|
+
const conversation = await client.agents.assistants.createConversation("sales-assistant");
|
|
938
|
+
|
|
939
|
+
conversation
|
|
940
|
+
.on("task_start", (task) => console.log("started", task.task, task.task_key))
|
|
941
|
+
.on("task_stop", (task) =>
|
|
942
|
+
console.log("finished", task.task_key, task.duration, task.success)
|
|
943
|
+
)
|
|
944
|
+
.on("content", (chunk) => process.stdout.write(chunk));
|
|
945
|
+
|
|
946
|
+
await conversation.streamMessage("What do we have in stock for vintage guitars?");
|
|
947
|
+
```
|
|
948
|
+
|
|
949
|
+
### `task_start` payload
|
|
950
|
+
|
|
951
|
+
| Field | Type | Description |
|
|
952
|
+
| --- | --- | --- |
|
|
953
|
+
| `type` | `string` | The event name, `task_start`. |
|
|
954
|
+
| `task` | `string` | Human-readable description of the task, safe to show in a UI. |
|
|
955
|
+
| `task_key` | `string` | Identifier of what ran. Its format depends on the task type. |
|
|
956
|
+
| `metadata` | `object` | Extra details about the task. Contents depend on the task type. |
|
|
957
|
+
| `start_time_utc` | `string` | When the task started (UTC). |
|
|
958
|
+
| `input` | `object` | The arguments the task was invoked with. Shape depends on the task. |
|
|
959
|
+
|
|
960
|
+
### `task_stop` payload
|
|
961
|
+
|
|
962
|
+
Same envelope as `task_start`, plus:
|
|
963
|
+
|
|
964
|
+
| Field | Type | Description |
|
|
965
|
+
| --- | --- | --- |
|
|
966
|
+
| `end_time_utc` | `string` | When the task finished (UTC). |
|
|
967
|
+
| `duration` | `string` | Elapsed time as a timespan string, e.g. `00:00:00.0002104`. |
|
|
968
|
+
| `success` | `boolean` | Whether the task completed successfully. |
|
|
969
|
+
| `output` | `any` | The task's result. Shape depends on the task. |
|
|
970
|
+
|
|
971
|
+
Unknown fields the server may add in the future are preserved on the payload — both types carry an index signature.
|
|
972
|
+
|
|
973
|
+
### Recognising a task type
|
|
974
|
+
|
|
975
|
+
Skill executions are one task type. Their `task_key` follows the `skills_<SkillCode>_execute` convention, and the skill is described under `metadata.skill`:
|
|
976
|
+
|
|
977
|
+
```json
|
|
978
|
+
{
|
|
979
|
+
"type": "task_start",
|
|
980
|
+
"task": "Executing Skill: GetProductInfo",
|
|
981
|
+
"task_key": "skills_GetProductInfo_execute",
|
|
982
|
+
"metadata": { "skill": { "type": "Prompt", "code": "GetProductInfo" } },
|
|
983
|
+
"start_time_utc": "2026-08-24T10:22:54.1822224Z",
|
|
984
|
+
"input": { "categoryName": "Music instruments from the 1960s" }
|
|
985
|
+
}
|
|
986
|
+
```
|
|
987
|
+
|
|
988
|
+
```tsx
|
|
989
|
+
conversation.on("task_start", (task) => {
|
|
990
|
+
const skillCode = task.metadata?.skill?.code;
|
|
991
|
+
if (skillCode) {
|
|
992
|
+
showSpinner(`Running ${skillCode}…`);
|
|
993
|
+
}
|
|
994
|
+
});
|
|
995
|
+
```
|
|
996
|
+
|
|
872
997
|
## Citations
|
|
873
998
|
|
|
874
999
|
When an agent grounds its response in knowledge sources (knowledge files or websites), it returns **citations** that map spans of the generated message back to the source passages they came from. Citations are available across all agent types that support knowledge grounding.
|