@serenity-star/sdk 2.6.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serenity-star/sdk",
3
- "version": "2.6.0",
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,6 +843,85 @@ 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
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.