@serenity-star/sdk 2.2.1 → 2.4.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/readme.md CHANGED
@@ -12,9 +12,14 @@ The Serenity Star JS/TS SDK provides a comprehensive interface for interacting w
12
12
  - [Assistants / Copilots](#assistants--copilots)
13
13
  - [Start a new conversation with an Agent](#start-a-new-conversation-with-an-agent)
14
14
  - [Get conversation information](#get-conversation-information)
15
+ - [Get conversation by id](#get-conversation-by-id)
15
16
  - [Sending messages within a conversation](#sending-messages-within-a-conversation)
16
17
  - [Stream message with SSE](#stream-message-with-sse)
17
18
  - [Real time conversation](#real-time-conversation)
19
+ - [Message Feedback](#message-feedback)
20
+ - [Submit feedback](#submit-feedback)
21
+ - [Remove feedback](#remove-feedback)
22
+ - [Connector Status](#connector-status)
18
23
  - [Activities](#activities)
19
24
  - [Execute an activity](#execute-an-activity)
20
25
  - [Stream responses with SSE](#stream-responses-with-sse)
@@ -25,6 +30,12 @@ The Serenity Star JS/TS SDK provides a comprehensive interface for interacting w
25
30
  - [Chat Completions](#chat-completions)
26
31
  - [Execute a chat completion](#execute-a-chat-completion)
27
32
  - [Stream responses with SSE](#stream-responses-with-sse-2)
33
+ - [Shared Features](#shared-features)
34
+ - [Upload Files (Volatile Knowledge)](#upload-files-volatile-knowledge)
35
+ - [Audio Input](#audio-input)
36
+ - [Send Audio Messages (Assistants/Copilots)](#send-audio-messages-assistantscopilots)
37
+ - [Execute with Audio (Activities/Proxies/Chat Completions)](#execute-with-audio-activitiesproxieschat-completions)
38
+ - [Audio Transcription Service](#audio-transcription-service)
28
39
 
29
40
  # Installation
30
41
 
@@ -38,8 +49,7 @@ npm install @serenity-star/sdk
38
49
  import SerenityClient from '@serenity-star/sdk';
39
50
 
40
51
  const client = new SerenityClient({
41
- apiKey: '<SERENITY_API_KEY>',
42
- apiVersion: 2 // Optional. 2 by default
52
+ apiKey: '<SERENITY_API_KEY>'
43
53
  });
44
54
 
45
55
  // Execute an activity agent
@@ -510,7 +520,6 @@ const client = new SerenityClient({
510
520
  const response = await client.agents.chatCompletions.execute("AgentCreator", {
511
521
  message: "Hello!!!"
512
522
  });
513
-
514
523
  console.log(
515
524
  response.content, // AI-generated response
516
525
  response.completion_usage, // { completion_tokens: 200, prompt_tokens: 30, total_tokens: 230 }
@@ -530,7 +539,7 @@ const response = await client.agents.chatCompletions.execute("Health-Coach", {
530
539
 
531
540
  console.log(
532
541
  response.content, // AI-generated response
533
- response.completion_usage // { completion_tokens: 200, prompt_tokens: 30, total_tokens: 230 }
542
+ response.completion_usage, // { completion_tokens: 200, prompt_tokens: 30, total_tokens: 230 }
534
543
  );
535
544
 
536
545
  ```
@@ -567,6 +576,230 @@ const response = await chatCompletion.stream();
567
576
  // Access final response data
568
577
  console.log(
569
578
  response.content, // AI-generated response
570
- response.completion_usage // { completion_tokens: 200, prompt_tokens: 30, total_tokens: 230 }
579
+ response.completion_usage, // { completion_tokens: 200, prompt_tokens: 30, total_tokens: 230 }
580
+ );
581
+ ```
582
+
583
+ ---
584
+
585
+ # Shared Features
586
+
587
+ ## Upload Files (Volatile Knowledge)
588
+
589
+ 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.
590
+
591
+ ```tsx
592
+ import SerenityClient from '@serenity-star/sdk';
593
+
594
+ const client = new SerenityClient({
595
+ apiKey: '<SERENITY_API_KEY>',
596
+ });
597
+
598
+ // Works with any agent type (Assistant, Copilot, Activity, Proxy, Chat Completion)
599
+ const conversation = await client.agents.assistants.createConversation("document-analyzer");
600
+
601
+ // Upload a file (basic example)
602
+ const file = new File(["content"], "document.pdf", { type: "application/pdf" });
603
+ const uploadResult = await conversation.volatileKnowledge.upload(file);
604
+
605
+ // Check if upload was successful
606
+ if (uploadResult.success) {
607
+ console.log(
608
+ uploadResult.id, // File ID
609
+ uploadResult.fileName, // "document.pdf"
610
+ uploadResult.fileSize, // Size in bytes
611
+ uploadResult.expirationDate, // When the file will be deleted
612
+ uploadResult.status // "analyzing", "invalid", "success", "error", or "expired"
613
+ );
614
+
615
+ // Send a message or execute - the uploaded file will be automatically included
616
+ const response = await conversation.sendMessage("What are the main points in this document?");
617
+ console.log(response.content); // Analysis based on the uploaded file
618
+ } else {
619
+ // Handle upload errors
620
+ console.error("Upload failed:", uploadResult.error);
621
+ }
622
+
623
+ // Upload with options
624
+ const imageFile = new File(["image data"], "chart.png", { type: "image/png" });
625
+ const uploadWithOptions = await conversation.volatileKnowledge.upload(imageFile, {
626
+ useVision: true, // Enable vision for image files (automatically skips embeddings for images)
627
+ noExpiration: false, // File will expire (default behavior)
628
+ expirationDays: 7, // Custom expiration in days
629
+ locale: {
630
+ uploadFileErrorMessage: "Failed to upload file. Please try again." // You can optionally provide localized error messages
631
+ }
632
+ });
633
+
634
+ if (uploadWithOptions.success) {
635
+ // The file is now ready to be used in the next message/execution
636
+ const response = await conversation.sendMessage("Describe what you see in this chart");
637
+ console.log(response.content);
638
+ }
639
+
640
+ // Check file status by ID
641
+ const fileStatus = await conversation.volatileKnowledge.getById(uploadResult.id);
642
+
643
+ if (fileStatus.success) {
644
+ console.log(
645
+ fileStatus.status, // "analyzing", "invalid", "success", "error", or "expired"
646
+ fileStatus.fileName, // "document.pdf"
647
+ fileStatus.fileSize, // Size in bytes
648
+ fileStatus.expirationDate // When the file will be deleted
649
+ );
650
+ } else {
651
+ console.error("Failed to fetch file status:", fileStatus.error);
652
+ }
653
+
654
+ // Remove a specific file from the queue
655
+ const file1 = new File(["content 1"], "doc1.pdf", { type: "application/pdf" });
656
+ const file2 = new File(["content 2"], "doc2.pdf", { type: "application/pdf" });
657
+
658
+ const upload1 = await conversation.volatileKnowledge.upload(file1);
659
+ const upload2 = await conversation.volatileKnowledge.upload(file2);
660
+
661
+ if (upload1.success && upload2.success) {
662
+ // Remove only the first file
663
+ conversation.volatileKnowledge.removeById(upload1.id);
664
+
665
+ // Now only file2 will be included in the next message/execution
666
+ const response = await conversation.sendMessage("Analyze these documents");
667
+ console.log(response.content);
668
+ }
669
+
670
+ // Clear all files from the queue
671
+ await conversation.volatileKnowledge.upload(file1);
672
+ await conversation.volatileKnowledge.upload(file2);
673
+
674
+ // Clear all pending files
675
+ conversation.volatileKnowledge.clear();
676
+
677
+ // No files will be included in this message/execution
678
+ const response = await conversation.sendMessage("Hello");
679
+ ```
680
+
681
+ ## Audio Input
682
+
683
+ The SDK provides audio input capabilities across different agent types, allowing you to send audio messages and transcribe audio files.
684
+
685
+ ### Send Audio Messages (Assistants/Copilots)
686
+
687
+ Send audio messages directly in conversations with assistants and copilots. The audio will be automatically transcribed and processed by the agent.
688
+
689
+ ```tsx
690
+ import SerenityClient from '@serenity-star/sdk';
691
+
692
+ const client = new SerenityClient({
693
+ apiKey: '<SERENITY_API_KEY>',
694
+ });
695
+
696
+ // Create conversation with an assistant
697
+ const conversation = await client.agents.assistants.createConversation("chef-assistant");
698
+
699
+ // Send an audio message (basic example)
700
+ const audioBlob = new Blob([audioData], { type: 'audio/webm' });
701
+ const response = await conversation.sendAudioMessage(audioBlob);
702
+
703
+ console.log(
704
+ response.content, // AI-generated response
705
+ response.completion_usage, // Token usage information
706
+ response.executor_task_logs // Task execution logs
571
707
  );
708
+
709
+ // Send an audio message with options
710
+ const responseWithOptions = await conversation.sendAudioMessage(audioBlob, {
711
+ inputParameters: {
712
+ cuisine: "italian"
713
+ },
714
+ volatileKnowledgeIds: ["knowledge-id-1"]
715
+ });
716
+
717
+ // Stream an audio message with SSE
718
+ conversation
719
+ .on("content", (chunk) => {
720
+ console.log(chunk); // Response chunk
721
+ })
722
+ .on("error", (error) => {
723
+ console.error("Error:", error);
724
+ });
725
+
726
+ const streamResponse = await conversation.streamAudioMessage(audioBlob);
727
+ console.log(streamResponse.content); // Final response
728
+ ```
729
+
730
+ ### Execute with Audio (Activities/Proxies/Chat Completions)
731
+
732
+ Execute activities, proxies, and chat completions with audio input. The audio will be processed and used as input for the agent execution.
733
+
734
+ ```tsx
735
+ import SerenityClient from '@serenity-star/sdk';
736
+
737
+ const client = new SerenityClient({
738
+ apiKey: '<SERENITY_API_KEY>',
739
+ });
740
+
741
+ // Example with Activity
742
+ const activity = client.agents.activities.create("voice-analyzer");
743
+ const audioBlob = new Blob([audioData], { type: 'audio/webm' });
744
+
745
+ // Execute with audio
746
+ const activityResponse = await activity.executeWithAudio(audioBlob);
747
+ console.log(activityResponse.content);
748
+
749
+ // Stream with audio
750
+ activity
751
+ .on("content", (chunk) => console.log(chunk))
752
+ .on("error", (error) => console.error(error));
753
+
754
+ const streamResponse = await activity.streamWithAudio(audioBlob);
755
+ console.log(streamResponse.content);
756
+
757
+ // Example with Proxy
758
+ const proxy = client.agents.proxies.create("proxy-agent", {
759
+ model: "gpt-4o-mini-2024-07-18",
760
+ messages: [{ role: "user", content: "Analyze this audio" }]
761
+ });
762
+
763
+ const proxyResponse = await proxy.executeWithAudio(audioBlob);
764
+ console.log(proxyResponse.content);
765
+
766
+ // Example with Chat Completion
767
+ const chatCompletion = client.agents.chatCompletions.create("audio-assistant", {
768
+ message: "Process this audio"
769
+ });
770
+
771
+ const chatResponse = await chatCompletion.executeWithAudio(audioBlob);
772
+ console.log(chatResponse.content);
773
+ ```
774
+
775
+ ## Audio Transcription Service
776
+
777
+ Use the dedicated audio transcription service to transcribe audio files independently from agent executions. The transcript can then be used as text input in conversations.
778
+
779
+ ```tsx
780
+ import SerenityClient from '@serenity-star/sdk';
781
+
782
+ const client = new SerenityClient({
783
+ apiKey: '<SERENITY_API_KEY>',
784
+ });
785
+
786
+ // Transcribe an audio file
787
+ const audioFile = new File([audioBlob], "recording.mp3", { type: "audio/mpeg" });
788
+
789
+ const result = await client.services.audio.transcribe(audioFile, {
790
+ modelId: '[YOUR_MODEL_ID]', // Optional: Specify transcription model
791
+ prompt: 'This is a conversation about AI', // Optional: Provide context
792
+ userIdentifier: 'user123' // Optional: User identifier
793
+ });
794
+
795
+ console.log('Transcript:', result.transcript);
796
+ console.log('Language:', result.metadata?.language);
797
+ console.log('Duration:', result.metadata?.duration, 'seconds');
798
+ console.log('Total tokens:', result.tokenUsage?.totalTokens);
799
+ console.log('Cost:', result.cost?.total, result.cost?.currency);
800
+
801
+ // Use the transcript in a conversation
802
+ const conversation = await client.agents.assistants.createConversation("chef-assistant");
803
+ const response = await conversation.sendMessage(result.transcript);
804
+ console.log(response.content); // AI response based on the transcribed audio
572
805
  ```