@serenity-star/sdk 2.4.4 → 2.5.1
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 +111 -218
- package/dist/index.d.ts +111 -218
- 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 +180 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serenity-star/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
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
|
@@ -8,6 +8,10 @@ The Serenity Star JS/TS SDK provides a comprehensive interface for interacting w
|
|
|
8
8
|
- [Serenity Star JS/TS SDK](#serenity-star-jsts-sdk)
|
|
9
9
|
- [Table of Contents](#table-of-contents)
|
|
10
10
|
- [Installation](#installation)
|
|
11
|
+
- [Authentication Modes](#authentication-modes)
|
|
12
|
+
- [API Key (Full Access)](#api-key-full-access)
|
|
13
|
+
- [Agent Client Credentials (Token Provider)](#agent-client-credentials-token-provider)
|
|
14
|
+
- [Feature Comparison](#feature-comparison)
|
|
11
15
|
- [Usage](#usage)
|
|
12
16
|
- [Assistants / Copilots](#assistants--copilots)
|
|
13
17
|
- [Start a new conversation with an Agent](#start-a-new-conversation-with-an-agent)
|
|
@@ -45,6 +49,81 @@ The Serenity Star JS/TS SDK provides a comprehensive interface for interacting w
|
|
|
45
49
|
npm install @serenity-star/sdk
|
|
46
50
|
```
|
|
47
51
|
|
|
52
|
+
# Authentication Modes
|
|
53
|
+
|
|
54
|
+
The SDK supports two authentication modes that determine how the client is instantiated and which features are available.
|
|
55
|
+
|
|
56
|
+
## API Key (Full Access)
|
|
57
|
+
|
|
58
|
+
Use an API key when you want full access to all agents and services. API keys can have permission restrictions configured in Serenity\* Star.
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import SerenityClient from '@serenity-star/sdk';
|
|
62
|
+
|
|
63
|
+
const client = new SerenityClient({
|
|
64
|
+
apiKey: '<SERENITY_API_KEY>',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// agentCode is passed to each operation
|
|
68
|
+
const conversation = await client.agents.assistants.createConversation("chef-assistant");
|
|
69
|
+
|
|
70
|
+
// All services are available
|
|
71
|
+
const transcript = await client.services.audio.transcribe(audioFile, { modelId: '<MODEL_ID>' });
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Agent Client Credentials (Token Provider)
|
|
75
|
+
|
|
76
|
+
Use Agent Client Credentials when you want the client scoped to a **single agent** and to obtain short-lived access tokens through a callback you provide. This mode does not expose long-lived credentials in your client code.
|
|
77
|
+
|
|
78
|
+
> **Setup:** Agent Client Credentials are created per-agent in the **Agent Design Studio** inside Serenity\* Star. Each credential set includes a `ClientId`, `ClientSecret`, and `publicKey`.
|
|
79
|
+
> - **`ClientId` and `ClientSecret`** must be kept server-side only. Your backend uses them to issue a short-lived client token.
|
|
80
|
+
> - **`publicKey`** is safe to expose in your client-side code and is passed to the `SerenityClient` constructor.
|
|
81
|
+
|
|
82
|
+
The `agentCode` is fixed at construction time and is **not passed** to individual method calls. The SDK manages the full token lifecycle (acquisition, proactive refresh, retry on 401) transparently.
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
import SerenityClient from '@serenity-star/sdk';
|
|
86
|
+
|
|
87
|
+
const client = new SerenityClient({
|
|
88
|
+
agentClientCredentials: {
|
|
89
|
+
agentCode: "chef-assistant",
|
|
90
|
+
publicKey: "<PUBLIC_KEY>", // safe to expose client-side
|
|
91
|
+
tokenProvider: async ({ context }) => {
|
|
92
|
+
// Call your backend, which uses ClientId + ClientSecret to issue a token
|
|
93
|
+
const res = await fetch("/api/get-serenity-token", {
|
|
94
|
+
method: "POST",
|
|
95
|
+
headers: { "Content-Type": "application/json" },
|
|
96
|
+
body: JSON.stringify({
|
|
97
|
+
publicKey: context.publicKey,
|
|
98
|
+
agentCode: context.agentCode,
|
|
99
|
+
}),
|
|
100
|
+
});
|
|
101
|
+
return (await res.json()).token;
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// agentCode is NOT passed — it was fixed at construction time
|
|
107
|
+
const conversation = await client.agents.assistants.createConversation();
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
> **Note:** Your `tokenProvider` callback only needs to return a client token from your backend. The SDK handles the token exchange with the Serenity API automatically — calling the exchange endpoint, obtaining a short-lived access token, and refreshing it transparently.
|
|
111
|
+
|
|
112
|
+
## Feature Comparison
|
|
113
|
+
|
|
114
|
+
| Feature | API Key | Agent Client Credentials |
|
|
115
|
+
|---|---|---|
|
|
116
|
+
| `agents.assistants.createConversation(agentCode, options?)` | ✅ | ➡️ `createConversation(options?)` |
|
|
117
|
+
| `agents.assistants.getInfoByCode(agentCode, options?)` | ✅ | ➡️ `getInfo(options?)` |
|
|
118
|
+
| `agents.assistants.getConversationById(agentCode, id, options?)` | ✅ | ➡️ `getConversationById(id, options?)` |
|
|
119
|
+
| `agents.assistants.createRealtimeSession(agentCode, options?)` | ✅ | ❌ Not available |
|
|
120
|
+
| `agents.copilots.*` | ✅ Same as assistants | ➡️ Same scoping as assistants |
|
|
121
|
+
| `agents.activities.execute(agentCode, options?)` | ✅ | ➡️ `execute(options?)` |
|
|
122
|
+
| `agents.activities.create(agentCode, options?)` | ✅ | ➡️ `create(options?)` |
|
|
123
|
+
| `agents.chatCompletions.*` | ✅ Same as activities | ➡️ Same scoping as activities |
|
|
124
|
+
| `agents.proxies.*` | ✅ Same as activities | ➡️ Same scoping as activities |
|
|
125
|
+
| `services.audio.transcribe(...)` | ✅ | ❌ Not available (`services` is undefined) |
|
|
126
|
+
|
|
48
127
|
# Usage
|
|
49
128
|
|
|
50
129
|
```tsx
|
|
@@ -74,6 +153,13 @@ const client = new SerenityClient({
|
|
|
74
153
|
const conversation = await client.agents.assistants.createConversation("chef-assistant");
|
|
75
154
|
```
|
|
76
155
|
|
|
156
|
+
> **Token Provider Auth:** Omit `agentCode` — it was fixed at construction time.
|
|
157
|
+
> ```ts
|
|
158
|
+
> const conversation = await client.agents.assistants.createConversation();
|
|
159
|
+
> // or with options:
|
|
160
|
+
> const conversation = await client.agents.assistants.createConversation({ channel: "web" });
|
|
161
|
+
> ```
|
|
162
|
+
|
|
77
163
|
## Get conversation information
|
|
78
164
|
|
|
79
165
|
```tsx
|
|
@@ -115,6 +201,13 @@ console.log(
|
|
|
115
201
|
);
|
|
116
202
|
```
|
|
117
203
|
|
|
204
|
+
> **Token Provider Auth:** Use `getInfo(options?)` instead of `getInfoByCode(agentCode, options?)`.
|
|
205
|
+
> ```ts
|
|
206
|
+
> const agentInfo = await client.agents.assistants.getInfo();
|
|
207
|
+
> // with options:
|
|
208
|
+
> const agentInfo = await client.agents.assistants.getInfo({ agentVersion: 2 });
|
|
209
|
+
> ```
|
|
210
|
+
|
|
118
211
|
## Use channel-pinned agent version
|
|
119
212
|
|
|
120
213
|
By default, when no `agentVersion` is specified, the SDK executes the **latest** version of the agent. If your application uses channels that pin a specific agent version, you can opt in to that behavior with `useChannelVersion`:
|
|
@@ -140,6 +233,14 @@ console.log(response.content);
|
|
|
140
233
|
|
|
141
234
|
> **Note:** An explicit `agentVersion` always takes priority over the channel's target version. When `useChannelVersion` is `false` (the default), the channel metadata is still available in `conversation.info` but does not affect which agent version is executed.
|
|
142
235
|
|
|
236
|
+
> **Token Provider Auth:** Same options, omit `agentCode`.
|
|
237
|
+
> ```ts
|
|
238
|
+
> const conversation = await client.agents.assistants.createConversation({
|
|
239
|
+
> channel: "my-channel",
|
|
240
|
+
> useChannelVersion: true,
|
|
241
|
+
> });
|
|
242
|
+
> ```
|
|
243
|
+
|
|
143
244
|
## Get conversation by id
|
|
144
245
|
|
|
145
246
|
```tsx
|
|
@@ -168,6 +269,13 @@ console.log(
|
|
|
168
269
|
);
|
|
169
270
|
```
|
|
170
271
|
|
|
272
|
+
> **Token Provider Auth:** Omit `agentCode`.
|
|
273
|
+
> ```ts
|
|
274
|
+
> const conversation = await client.agents.assistants.getConversationById("<conversation-id>");
|
|
275
|
+
> // with options:
|
|
276
|
+
> const conversationWithLogs = await client.agents.assistants.getConversationById("<conversation-id>", { showExecutorTaskLogs: true });
|
|
277
|
+
> ```
|
|
278
|
+
|
|
171
279
|
## Sending messages within a conversation
|
|
172
280
|
|
|
173
281
|
```tsx
|
|
@@ -263,6 +371,8 @@ session.unmuteMicrophone()
|
|
|
263
371
|
session.stop();
|
|
264
372
|
```
|
|
265
373
|
|
|
374
|
+
> **Token Provider Auth:** `createRealtimeSession` is not available with this auth mode. Realtime features require API Key authentication.
|
|
375
|
+
|
|
266
376
|
## Message Feedback
|
|
267
377
|
|
|
268
378
|
You can collect user feedback on agent responses to help improve the quality of your assistant.
|
|
@@ -393,6 +503,13 @@ console.log(
|
|
|
393
503
|
)
|
|
394
504
|
```
|
|
395
505
|
|
|
506
|
+
> **Token Provider Auth:** Omit `agentCode`.
|
|
507
|
+
> ```ts
|
|
508
|
+
> const response = await client.agents.activities.execute();
|
|
509
|
+
> // with options:
|
|
510
|
+
> const response = await client.agents.activities.execute({ inputParameters: { targetLanguage: "russian", textToTranslate: "hello world" } });
|
|
511
|
+
> ```
|
|
512
|
+
|
|
396
513
|
## Stream responses with SSE
|
|
397
514
|
|
|
398
515
|
```tsx
|
|
@@ -426,6 +543,11 @@ console.log(
|
|
|
426
543
|
);
|
|
427
544
|
```
|
|
428
545
|
|
|
546
|
+
> **Token Provider Auth:** Omit `agentCode` from `create()`.
|
|
547
|
+
> ```ts
|
|
548
|
+
> const activity = client.agents.activities.create({ inputParameters: { targetLanguage: "russian", textToTranslate: "hello world" } })
|
|
549
|
+
> ```
|
|
550
|
+
|
|
429
551
|
---
|
|
430
552
|
|
|
431
553
|
|
|
@@ -456,6 +578,11 @@ console.log(
|
|
|
456
578
|
|
|
457
579
|
```
|
|
458
580
|
|
|
581
|
+
> **Token Provider Auth:** Omit `agentCode`.
|
|
582
|
+
> ```ts
|
|
583
|
+
> const response = await client.agents.proxies.execute({ model: "gpt-4o-mini-2024-07-18", messages: [{ role: "user", content: "What is artificial intelligence?" }] });
|
|
584
|
+
> ```
|
|
585
|
+
|
|
459
586
|
## Stream responses with SSE
|
|
460
587
|
|
|
461
588
|
```tsx
|
|
@@ -492,6 +619,11 @@ console.log(
|
|
|
492
619
|
|
|
493
620
|
```
|
|
494
621
|
|
|
622
|
+
> **Token Provider Auth:** Omit `agentCode` from `create()`.
|
|
623
|
+
> ```ts
|
|
624
|
+
> const proxy = client.agents.proxies.create({ model: "gpt-4o-mini-2024-07-18", messages: [{ role: "user", content: "What is artificial intelligence?" }] })
|
|
625
|
+
> ```
|
|
626
|
+
|
|
495
627
|
## Proxy Execution Options
|
|
496
628
|
|
|
497
629
|
The following options can be passed as the second parameter in `execute` or `create`:
|
|
@@ -571,6 +703,11 @@ console.log(
|
|
|
571
703
|
|
|
572
704
|
```
|
|
573
705
|
|
|
706
|
+
> **Token Provider Auth:** Omit `agentCode`.
|
|
707
|
+
> ```ts
|
|
708
|
+
> const response = await client.agents.chatCompletions.execute({ message: "Hello!!!" });
|
|
709
|
+
> ```
|
|
710
|
+
|
|
574
711
|
## Stream responses with SSE
|
|
575
712
|
|
|
576
713
|
```tsx
|
|
@@ -607,10 +744,50 @@ console.log(
|
|
|
607
744
|
);
|
|
608
745
|
```
|
|
609
746
|
|
|
747
|
+
> **Token Provider Auth:** Omit `agentCode` from `create()`.
|
|
748
|
+
> ```ts
|
|
749
|
+
> const chatCompletion = client.agents.chatCompletions.create({ message: "Hi! How can I eat healthier?" })
|
|
750
|
+
> ```
|
|
751
|
+
|
|
610
752
|
---
|
|
611
753
|
|
|
612
754
|
# Shared Features
|
|
613
755
|
|
|
756
|
+
## Download Attached Files
|
|
757
|
+
|
|
758
|
+
Download files attached to assistant/copilot messages through the SDK (auth handled automatically for both API Key and Token Provider modes).
|
|
759
|
+
|
|
760
|
+
```tsx
|
|
761
|
+
import SerenityClient from '@serenity-star/sdk';
|
|
762
|
+
|
|
763
|
+
const client = new SerenityClient({
|
|
764
|
+
apiKey: '<SERENITY_API_KEY>',
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
const conversation = await client.agents.assistants.createConversation("document-analyzer");
|
|
768
|
+
|
|
769
|
+
// Example attachment URL from message.attached_volatile_knowledges[index].download_url
|
|
770
|
+
const blob = await conversation.downloadAttachment("https://api.serenitystar.ai/api/file/download/<file-id>");
|
|
771
|
+
|
|
772
|
+
// Trigger browser download
|
|
773
|
+
const url = URL.createObjectURL(blob);
|
|
774
|
+
const a = document.createElement("a");
|
|
775
|
+
a.href = url;
|
|
776
|
+
a.download = "document.pdf";
|
|
777
|
+
a.click();
|
|
778
|
+
URL.revokeObjectURL(url);
|
|
779
|
+
```
|
|
780
|
+
|
|
781
|
+
> **Token Provider Auth:** Same API.
|
|
782
|
+
> ```ts
|
|
783
|
+
> const client = new SerenityClient({
|
|
784
|
+
> agentClientCredentials: { agentCode: "chef-assistant", publicKey: "<PUBLIC_KEY>", tokenProvider },
|
|
785
|
+
> });
|
|
786
|
+
>
|
|
787
|
+
> const conversation = await client.agents.assistants.createConversation();
|
|
788
|
+
> const blob = await conversation.downloadAttachment("https://api.serenitystar.ai/api/file/download/<file-id>");
|
|
789
|
+
> ```
|
|
790
|
+
|
|
614
791
|
## Stop Streaming Response
|
|
615
792
|
|
|
616
793
|
You can stop a streaming response at any time by calling `stop()`. This works across all agent types: **Assistants**, **Copilots**, **Activities**, **Proxies**, and **Chat Completions**.
|
|
@@ -873,4 +1050,6 @@ console.log('Cost:', result.cost?.total, result.cost?.currency);
|
|
|
873
1050
|
const conversation = await client.agents.assistants.createConversation("chef-assistant");
|
|
874
1051
|
const response = await conversation.sendMessage(result.transcript);
|
|
875
1052
|
console.log(response.content); // AI response based on the transcribed audio
|
|
876
|
-
```
|
|
1053
|
+
```
|
|
1054
|
+
|
|
1055
|
+
> **Token Provider Auth:** `client.services.audio` is not available with this auth mode. Audio transcription requires API Key authentication.
|