@serenity-star/sdk 2.5.2 → 2.6.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 +68 -6
- package/dist/index.d.ts +68 -6
- 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 +119 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serenity-star/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.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
|
@@ -36,7 +36,9 @@ The Serenity Star JS/TS SDK provides a comprehensive interface for interacting w
|
|
|
36
36
|
- [Execute a chat completion](#execute-a-chat-completion)
|
|
37
37
|
- [Stream responses with SSE](#stream-responses-with-sse-2)
|
|
38
38
|
- [Shared Features](#shared-features)
|
|
39
|
+
- [Download Attached Files](#download-attached-files)
|
|
39
40
|
- [Stop Streaming Response](#stop-streaming-response)
|
|
41
|
+
- [Citations](#citations)
|
|
40
42
|
- [Upload Files (Volatile Knowledge)](#upload-files-volatile-knowledge)
|
|
41
43
|
- [Audio Input](#audio-input)
|
|
42
44
|
- [Send Audio Messages (Assistants/Copilots)](#send-audio-messages-assistantscopilots)
|
|
@@ -312,8 +314,14 @@ const client = new SerenityClient({
|
|
|
312
314
|
const conversation = await client.agents.assistants.createConversation("chef-assistant")
|
|
313
315
|
|
|
314
316
|
conversation
|
|
315
|
-
.on("content", (chunk) => {
|
|
317
|
+
.on("content", (chunk, citations) => {
|
|
316
318
|
console.log(chunk) // Response chunk
|
|
319
|
+
// `citations` is an optional array attached to some chunks.
|
|
320
|
+
// Each citation's start_index / end_index are offsets into the FULL accumulated
|
|
321
|
+
// message, not into this individual chunk.
|
|
322
|
+
if (citations) {
|
|
323
|
+
console.log(citations) // CitationRes[]
|
|
324
|
+
}
|
|
317
325
|
})
|
|
318
326
|
.on("error", (error) => {
|
|
319
327
|
// Handle stream errors here
|
|
@@ -327,10 +335,13 @@ console.log(
|
|
|
327
335
|
response.content, // "Sure! Here is a recipe for parmesan chicken..."
|
|
328
336
|
response.completion_usage, // { completion_tokens: 200, prompt_tokens: 30, total_tokens: 230 }
|
|
329
337
|
response.executor_task_logs, // [ { description: 'Task 1', duration: 100 }, { description: 'Task 2', duration: 500 }],
|
|
338
|
+
response.citations, // CitationRes[] — full citation list for the final message
|
|
330
339
|
response.instance_id, // instance id for the conversation
|
|
331
340
|
)
|
|
332
341
|
```
|
|
333
342
|
|
|
343
|
+
> **Citations:** When the agent grounds its answer in knowledge sources, citations are delivered both incrementally on `content` events (second argument) and as a consolidated `response.citations` array on the final result. See [Citations](#citations) for the full shape.
|
|
344
|
+
|
|
334
345
|
## Real time conversation
|
|
335
346
|
|
|
336
347
|
```tsx
|
|
@@ -832,9 +843,88 @@ const activity = client.agents.activities.create("translator-activity", {
|
|
|
832
843
|
await activity.stream();
|
|
833
844
|
```
|
|
834
845
|
|
|
846
|
+
## Citations
|
|
847
|
+
|
|
848
|
+
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.
|
|
849
|
+
|
|
850
|
+
Citations are delivered in two places:
|
|
851
|
+
|
|
852
|
+
1. **Incrementally**, as the second argument of the `content` event during streaming.
|
|
853
|
+
2. **Consolidated**, as the `citations` array on the final result (`response.citations`) — available for both streamed and non-streamed executions.
|
|
854
|
+
|
|
855
|
+
```tsx
|
|
856
|
+
import SerenityClient from '@serenity-star/sdk';
|
|
857
|
+
|
|
858
|
+
const client = new SerenityClient({
|
|
859
|
+
apiKey: '<SERENITY_API_KEY>',
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
const conversation = await client.agents.assistants.createConversation("policy-assistant");
|
|
863
|
+
|
|
864
|
+
conversation.on("content", (chunk, citations) => {
|
|
865
|
+
process.stdout.write(chunk);
|
|
866
|
+
|
|
867
|
+
if (citations) {
|
|
868
|
+
for (const citation of citations) {
|
|
869
|
+
console.log(
|
|
870
|
+
citation.citation_index, // Display number rendered as the superscript (may repeat)
|
|
871
|
+
citation.start_index, // Offset into the FULL accumulated message where the cited span starts
|
|
872
|
+
citation.end_index, // Offset into the FULL accumulated message where the cited span ends
|
|
873
|
+
citation.relevance, // Optional relevance score
|
|
874
|
+
citation.cited_text, // Verbatim text of the source passage (shown in the hover card)
|
|
875
|
+
citation.source // The cited source (see below), or null
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
});
|
|
880
|
+
|
|
881
|
+
const response = await conversation.streamMessage("Summarize our security and access-control requirements");
|
|
882
|
+
|
|
883
|
+
// The final result carries the consolidated citation list
|
|
884
|
+
for (const citation of response.citations ?? []) {
|
|
885
|
+
if (citation.source?.type === "knowledge_file") {
|
|
886
|
+
console.log(`[${citation.citation_index}] ${citation.source.file_name} (pages ${citation.source.page_range})`);
|
|
887
|
+
} else if (citation.source?.type === "knowledge_website") {
|
|
888
|
+
console.log(`[${citation.citation_index}] ${citation.source.website}`);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
```
|
|
892
|
+
|
|
893
|
+
> **Note:** `start_index` and `end_index` are offsets into the **full accumulated message**, not into the individual chunk delivered by a `content` event. Accumulate the chunks (or use `response.content`) before resolving these offsets.
|
|
894
|
+
|
|
895
|
+
The `CitationRes` and `CitationSource` types are exported from the package:
|
|
896
|
+
|
|
897
|
+
```ts
|
|
898
|
+
import type { CitationRes, CitationSource } from '@serenity-star/sdk';
|
|
899
|
+
|
|
900
|
+
type CitationSource =
|
|
901
|
+
| {
|
|
902
|
+
type: "knowledge_file";
|
|
903
|
+
knowledge_file_version_id?: string;
|
|
904
|
+
section_id?: string;
|
|
905
|
+
file_name?: string;
|
|
906
|
+
page_range?: string;
|
|
907
|
+
}
|
|
908
|
+
| {
|
|
909
|
+
type: "knowledge_website";
|
|
910
|
+
knowledge_file_version_id?: string;
|
|
911
|
+
section_id?: string;
|
|
912
|
+
website: string;
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
type CitationRes = {
|
|
916
|
+
cited_text: string; // Verbatim text of the source passage (shown in the hover card)
|
|
917
|
+
citation_index: number; // Display number rendered as the superscript; may repeat across citations
|
|
918
|
+
start_index: number; // Offset into the FULL accumulated message where the cited span starts
|
|
919
|
+
end_index: number; // Offset into the FULL accumulated message where the cited span ends
|
|
920
|
+
relevance?: number;
|
|
921
|
+
source: CitationSource | null;
|
|
922
|
+
};
|
|
923
|
+
```
|
|
924
|
+
|
|
835
925
|
## Upload Files (Volatile Knowledge)
|
|
836
926
|
|
|
837
|
-
Upload files to be used as context in your agent executions. This feature is available for all agent types: **Assistants**, **Copilots**, **Activities**, **Proxies**, and **Chat Completions**. Files are automatically included in the next message or execution.
|
|
927
|
+
Upload files to be used as context in your agent executions. This feature is available for all agent types: **Assistants**, **Copilots**, **Activities**, **Proxies**, and **Chat Completions**. Files are agent-scoped automatically and are included in the next message or execution.
|
|
838
928
|
|
|
839
929
|
```tsx
|
|
840
930
|
import SerenityClient from '@serenity-star/sdk';
|
|
@@ -846,6 +936,10 @@ const client = new SerenityClient({
|
|
|
846
936
|
// Works with any agent type (Assistant, Copilot, Activity, Proxy, Chat Completion)
|
|
847
937
|
const conversation = await client.agents.assistants.createConversation("document-analyzer");
|
|
848
938
|
|
|
939
|
+
// Check the file types supported by this specific agent
|
|
940
|
+
const supportedMimeTypes = await conversation.volatileKnowledge.getSupportedMimeTypes();
|
|
941
|
+
console.log("Supported MIME types:", supportedMimeTypes);
|
|
942
|
+
|
|
849
943
|
// Upload a file (basic example)
|
|
850
944
|
const file = new File(["content"], "document.pdf", { type: "application/pdf" });
|
|
851
945
|
const uploadResult = await conversation.volatileKnowledge.upload(file);
|
|
@@ -872,6 +966,7 @@ if (uploadResult.success) {
|
|
|
872
966
|
const imageFile = new File(["image data"], "chart.png", { type: "image/png" });
|
|
873
967
|
const uploadWithOptions = await conversation.volatileKnowledge.upload(imageFile, {
|
|
874
968
|
useVision: true, // Enable vision for image files (automatically skips embeddings for images)
|
|
969
|
+
processEmbeddings: false, // Optional: explicitly control embeddings generation
|
|
875
970
|
noExpiration: false, // File will expire (default behavior)
|
|
876
971
|
expirationDays: 7, // Custom expiration in days
|
|
877
972
|
locale: {
|
|
@@ -885,6 +980,28 @@ if (uploadWithOptions.success) {
|
|
|
885
980
|
console.log(response.content);
|
|
886
981
|
}
|
|
887
982
|
|
|
983
|
+
// Create volatile knowledge from an existing platform file ID
|
|
984
|
+
const fromFileId = await conversation.volatileKnowledge.uploadFromFileId("existing-file-id", {
|
|
985
|
+
callbackUrl: "https://example.com/volatile-knowledge/callback",
|
|
986
|
+
processEmbeddings: true,
|
|
987
|
+
expirationDays: 7,
|
|
988
|
+
});
|
|
989
|
+
|
|
990
|
+
// Create volatile knowledge from a remote URL
|
|
991
|
+
const fromUrl = await conversation.volatileKnowledge.uploadFromUrl("https://example.com/report.pdf", {
|
|
992
|
+
fileName: "report.pdf",
|
|
993
|
+
processEmbeddings: true,
|
|
994
|
+
noExpiration: false,
|
|
995
|
+
});
|
|
996
|
+
|
|
997
|
+
// Create volatile knowledge from base64 content
|
|
998
|
+
const fromBase64 = await conversation.volatileKnowledge.uploadFromBase64(contentBase64, {
|
|
999
|
+
fileName: "report.pdf",
|
|
1000
|
+
mimeType: "application/pdf",
|
|
1001
|
+
processEmbeddings: true,
|
|
1002
|
+
expirationDays: 7,
|
|
1003
|
+
});
|
|
1004
|
+
|
|
888
1005
|
// Check file status by ID
|
|
889
1006
|
const fileStatus = await conversation.volatileKnowledge.getById(uploadResult.id);
|
|
890
1007
|
|