@serenity-star/sdk 2.6.0 → 2.6.2
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 +34 -3
- package/dist/index.d.ts +34 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/readme.md +124 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serenity-star/sdk",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2",
|
|
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,10 @@ 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)
|
|
42
|
+
- [Citations on stored messages](#citations-on-stored-messages)
|
|
40
43
|
- [Upload Files (Volatile Knowledge)](#upload-files-volatile-knowledge)
|
|
41
44
|
- [Audio Input](#audio-input)
|
|
42
45
|
- [Send Audio Messages (Assistants/Copilots)](#send-audio-messages-assistantscopilots)
|
|
@@ -255,7 +258,7 @@ const conversation = await client.agents.assistants.getConversationById("<agent-
|
|
|
255
258
|
|
|
256
259
|
console.log(
|
|
257
260
|
conversation.id, // "<conversation-id>"
|
|
258
|
-
conversation.messages, // Array of messages
|
|
261
|
+
conversation.messages, // Array of messages (each may include a `citations` array — see Citations)
|
|
259
262
|
conversation.open // Boolean that indicates if the conversation was closed or not
|
|
260
263
|
);
|
|
261
264
|
|
|
@@ -312,8 +315,14 @@ const client = new SerenityClient({
|
|
|
312
315
|
const conversation = await client.agents.assistants.createConversation("chef-assistant")
|
|
313
316
|
|
|
314
317
|
conversation
|
|
315
|
-
.on("content", (chunk) => {
|
|
318
|
+
.on("content", (chunk, citations) => {
|
|
316
319
|
console.log(chunk) // Response chunk
|
|
320
|
+
// `citations` is an optional array attached to some chunks.
|
|
321
|
+
// Each citation's start_index / end_index are offsets into the FULL accumulated
|
|
322
|
+
// message, not into this individual chunk.
|
|
323
|
+
if (citations) {
|
|
324
|
+
console.log(citations) // CitationRes[]
|
|
325
|
+
}
|
|
317
326
|
})
|
|
318
327
|
.on("error", (error) => {
|
|
319
328
|
// Handle stream errors here
|
|
@@ -327,10 +336,13 @@ console.log(
|
|
|
327
336
|
response.content, // "Sure! Here is a recipe for parmesan chicken..."
|
|
328
337
|
response.completion_usage, // { completion_tokens: 200, prompt_tokens: 30, total_tokens: 230 }
|
|
329
338
|
response.executor_task_logs, // [ { description: 'Task 1', duration: 100 }, { description: 'Task 2', duration: 500 }],
|
|
339
|
+
response.citations, // CitationRes[] — full citation list for the final message
|
|
330
340
|
response.instance_id, // instance id for the conversation
|
|
331
341
|
)
|
|
332
342
|
```
|
|
333
343
|
|
|
344
|
+
> **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.
|
|
345
|
+
|
|
334
346
|
## Real time conversation
|
|
335
347
|
|
|
336
348
|
```tsx
|
|
@@ -832,6 +844,116 @@ const activity = client.agents.activities.create("translator-activity", {
|
|
|
832
844
|
await activity.stream();
|
|
833
845
|
```
|
|
834
846
|
|
|
847
|
+
## Citations
|
|
848
|
+
|
|
849
|
+
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.
|
|
850
|
+
|
|
851
|
+
Citations are delivered in three places:
|
|
852
|
+
|
|
853
|
+
1. **Incrementally**, as the second argument of the `content` event during streaming.
|
|
854
|
+
2. **Consolidated**, as the `citations` array on the final result (`response.citations`) — available for both streamed and non-streamed executions.
|
|
855
|
+
3. **Persisted**, on each `Message` loaded from conversation history (`message.citations`) — see [Citations on stored messages](#citations-on-stored-messages) below.
|
|
856
|
+
|
|
857
|
+
```tsx
|
|
858
|
+
import SerenityClient from '@serenity-star/sdk';
|
|
859
|
+
|
|
860
|
+
const client = new SerenityClient({
|
|
861
|
+
apiKey: '<SERENITY_API_KEY>',
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
const conversation = await client.agents.assistants.createConversation("policy-assistant");
|
|
865
|
+
|
|
866
|
+
conversation.on("content", (chunk, citations) => {
|
|
867
|
+
process.stdout.write(chunk);
|
|
868
|
+
|
|
869
|
+
if (citations) {
|
|
870
|
+
for (const citation of citations) {
|
|
871
|
+
console.log(
|
|
872
|
+
citation.citation_index, // Display number rendered as the superscript (may repeat)
|
|
873
|
+
citation.start_index, // Offset into the FULL accumulated message where the cited span starts
|
|
874
|
+
citation.end_index, // Offset into the FULL accumulated message where the cited span ends
|
|
875
|
+
citation.relevance, // Optional relevance score
|
|
876
|
+
citation.cited_text, // Verbatim text of the source passage (shown in the hover card)
|
|
877
|
+
citation.source // The cited source (see below), or null
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
const response = await conversation.streamMessage("Summarize our security and access-control requirements");
|
|
884
|
+
|
|
885
|
+
// The final result carries the consolidated citation list
|
|
886
|
+
for (const citation of response.citations ?? []) {
|
|
887
|
+
if (citation.source?.type === "knowledge_file") {
|
|
888
|
+
console.log(`[${citation.citation_index}] ${citation.source.file_name} (pages ${citation.source.page_range})`);
|
|
889
|
+
} else if (citation.source?.type === "knowledge_website") {
|
|
890
|
+
console.log(`[${citation.citation_index}] ${citation.source.website}`);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
```
|
|
894
|
+
|
|
895
|
+
> **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.
|
|
896
|
+
|
|
897
|
+
The `CitationRes`, `CitationResWithoutText`, and `CitationSource` types are exported from the package:
|
|
898
|
+
|
|
899
|
+
```ts
|
|
900
|
+
import type { CitationRes, CitationResWithoutText, CitationSource } from '@serenity-star/sdk';
|
|
901
|
+
|
|
902
|
+
type CitationSource =
|
|
903
|
+
| {
|
|
904
|
+
type: "knowledge_file";
|
|
905
|
+
knowledge_file_version_id?: string;
|
|
906
|
+
section_id?: string;
|
|
907
|
+
file_name?: string;
|
|
908
|
+
page_range?: string;
|
|
909
|
+
}
|
|
910
|
+
| {
|
|
911
|
+
type: "knowledge_website";
|
|
912
|
+
knowledge_file_version_id?: string;
|
|
913
|
+
section_id?: string;
|
|
914
|
+
website: string;
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
type CitationRes = {
|
|
918
|
+
cited_text: string; // Verbatim text of the source passage (shown in the hover card)
|
|
919
|
+
citation_index: number; // Display number rendered as the superscript; may repeat across citations
|
|
920
|
+
start_index: number; // Offset into the FULL accumulated message where the cited span starts
|
|
921
|
+
end_index: number; // Offset into the FULL accumulated message where the cited span ends
|
|
922
|
+
relevance?: number;
|
|
923
|
+
source: CitationSource | null;
|
|
924
|
+
};
|
|
925
|
+
|
|
926
|
+
// Same shape as CitationRes but without `cited_text`. Used for citations on
|
|
927
|
+
// messages loaded from conversation history (see "Get conversation by id").
|
|
928
|
+
type CitationResWithoutText = {
|
|
929
|
+
citation_index: number;
|
|
930
|
+
start_index: number;
|
|
931
|
+
end_index: number;
|
|
932
|
+
relevance?: number;
|
|
933
|
+
source: CitationSource | null;
|
|
934
|
+
};
|
|
935
|
+
```
|
|
936
|
+
|
|
937
|
+
### Citations on stored messages
|
|
938
|
+
|
|
939
|
+
Citations are also persisted on the conversation history. When you load past messages via [Get conversation by id](#get-conversation-by-id) (or read `conversation.messages`), each `Message` may carry a `citations` array of type `CitationResWithoutText[]` — the same shape as `CitationRes` but **without** the `cited_text` field (the verbatim passage is not stored alongside historical messages).
|
|
940
|
+
|
|
941
|
+
```tsx
|
|
942
|
+
const conversation = await client.agents.assistants.getConversationById("policy-assistant", "<conversation-id>");
|
|
943
|
+
|
|
944
|
+
for (const message of conversation.messages) {
|
|
945
|
+
for (const citation of message.citations ?? []) {
|
|
946
|
+
console.log(
|
|
947
|
+
citation.citation_index, // Display number rendered as the superscript (may repeat)
|
|
948
|
+
citation.start_index, // Offset into the message `value` where the cited span starts
|
|
949
|
+
citation.end_index, // Offset into the message `value` where the cited span ends
|
|
950
|
+
citation.relevance, // Optional relevance score
|
|
951
|
+
citation.source // The cited source (knowledge_file / knowledge_website), or null
|
|
952
|
+
);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
```
|
|
956
|
+
|
|
835
957
|
## Upload Files (Volatile Knowledge)
|
|
836
958
|
|
|
837
959
|
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.
|