@serenity-star/sdk 2.2.1 → 2.3.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
@@ -38,8 +38,7 @@ npm install @serenity-star/sdk
38
38
  import SerenityClient from '@serenity-star/sdk';
39
39
 
40
40
  const client = new SerenityClient({
41
- apiKey: '<SERENITY_API_KEY>',
42
- apiVersion: 2 // Optional. 2 by default
41
+ apiKey: '<SERENITY_API_KEY>'
43
42
  });
44
43
 
45
44
  // Execute an activity agent
@@ -325,6 +324,100 @@ const newResponse = await conversation.sendMessage("I need a summary of my lates
325
324
  console.log(newResponse.content); // Summary of the meeting notes
326
325
  ```
327
326
 
327
+ ## Upload Files (volatile knowledge)
328
+
329
+ Upload files to be used as context in your conversations. Files are automatically included in the next message sent.
330
+
331
+ ```tsx
332
+ import SerenityClient from '@serenity-star/sdk';
333
+
334
+ const client = new SerenityClient({
335
+ apiKey: '<SERENITY_API_KEY>',
336
+ });
337
+
338
+ // Create conversation with an assistant
339
+ const conversation = await client.agents.assistants.createConversation("document-analyzer");
340
+
341
+ // Upload a file (basic example)
342
+ const file = new File(["content"], "document.pdf", { type: "application/pdf" });
343
+ const uploadResult = await conversation.volatileKnowledge.upload(file);
344
+
345
+ // Check if upload was successful
346
+ if (uploadResult.success) {
347
+ console.log(
348
+ uploadResult.id, // File ID
349
+ uploadResult.fileName, // "document.pdf"
350
+ uploadResult.fileSize, // Size in bytes
351
+ uploadResult.expirationDate, // When the file will be deleted
352
+ uploadResult.status // "processing" or "ready"
353
+ );
354
+
355
+ // Send a message - the uploaded file will be automatically included
356
+ const response = await conversation.sendMessage("What are the main points in this document?");
357
+ console.log(response.content); // Analysis based on the uploaded file
358
+ } else {
359
+ // Handle upload errors
360
+ console.error("Upload failed:", uploadResult.error);
361
+ }
362
+
363
+ // Upload with options
364
+ const imageFile = new File(["image data"], "chart.png", { type: "image/png" });
365
+ const uploadWithOptions = await conversation.volatileKnowledge.upload(imageFile, {
366
+ useVision: true, // Enable vision for image files (automatically skips embeddings for images)
367
+ noExpiration: false, // File will expire (default behavior)
368
+ expirationDays: 7, // Custom expiration in days
369
+ locale: {
370
+ uploadFileErrorMessage: "Failed to upload file. Please try again." // You can optionally provide localized error messages
371
+ }
372
+ });
373
+
374
+ if (uploadWithOptions.success) {
375
+ // The file is now ready to be used in the next message
376
+ const response = await conversation.sendMessage("Describe what you see in this chart");
377
+ console.log(response.content);
378
+ }
379
+
380
+ // Check file status by ID
381
+ const fileStatus = await conversation.volatileKnowledge.getById(uploadResult.id);
382
+
383
+ if (fileStatus.success) {
384
+ console.log(
385
+ fileStatus.status, // "analyzing", "invalid", "success", "error", or "expired"
386
+ fileStatus.fileName, // "document.pdf"
387
+ fileStatus.fileSize, // Size in bytes
388
+ fileStatus.expirationDate // When the file will be deleted
389
+ );
390
+ } else {
391
+ console.error("Failed to fetch file status:", fileStatus.error);
392
+ }
393
+
394
+ // Remove a specific file from the queue
395
+ const file1 = new File(["content 1"], "doc1.pdf", { type: "application/pdf" });
396
+ const file2 = new File(["content 2"], "doc2.pdf", { type: "application/pdf" });
397
+
398
+ const upload1 = await conversation.volatileKnowledge.upload(file1);
399
+ const upload2 = await conversation.volatileKnowledge.upload(file2);
400
+
401
+ if (upload1.success && upload2.success) {
402
+ // Remove only the first file
403
+ conversation.volatileKnowledge.removeById(upload1.id);
404
+
405
+ // Now only file2 will be included in the next message
406
+ const response = await conversation.sendMessage("Analyze these documents");
407
+ console.log(response.content);
408
+ }
409
+
410
+ // Clear all files from the queue
411
+ await conversation.volatileKnowledge.upload(file1);
412
+ await conversation.volatileKnowledge.upload(file2);
413
+
414
+ // Clear all pending files
415
+ conversation.volatileKnowledge.clear();
416
+
417
+ // No files will be included in this message
418
+ const response = await conversation.sendMessage("Hello");
419
+ ```
420
+
328
421
  ---
329
422
 
330
423
  # Activities
@@ -389,6 +482,100 @@ console.log(
389
482
  );
390
483
  ```
391
484
 
485
+ ## Upload Files (volatile knowledge)
486
+
487
+ Upload files to be used as context in your activity execution. Files are automatically included in the next execution.
488
+
489
+ ```tsx
490
+ import SerenityClient from '@serenity-star/sdk';
491
+
492
+ const client = new SerenityClient({
493
+ apiKey: '<SERENITY_API_KEY>',
494
+ });
495
+
496
+ // Create activity instance
497
+ const activity = client.agents.activities.create("data-analyzer");
498
+
499
+ // Upload a file
500
+ const file = new File(["content"], "data.csv", { type: "text/csv" });
501
+ const uploadResult = await activity.volatileKnowledge.upload(file);
502
+
503
+ // Check if upload was successful
504
+ if (uploadResult.success) {
505
+ console.log(
506
+ uploadResult.id, // File ID
507
+ uploadResult.fileName, // "data.csv"
508
+ uploadResult.fileSize, // Size in bytes
509
+ uploadResult.expirationDate, // When the file will be deleted
510
+ uploadResult.status // "analyzing", "invalid", "success", "error", or "expired"
511
+ );
512
+
513
+ // Execute the activity - the uploaded file will be automatically included
514
+ const response = await activity.execute();
515
+ console.log(response.content); // Analysis based on the uploaded file
516
+ } else {
517
+ // Handle upload errors
518
+ console.error("Upload failed:", uploadResult.error);
519
+ }
520
+
521
+ // Upload with options
522
+ const imageFile = new File(["image data"], "chart.png", { type: "image/png" });
523
+ const uploadWithOptions = await activity.volatileKnowledge.upload(imageFile, {
524
+ useVision: true, // Enable vision for image files (automatically skips embeddings for images)
525
+ noExpiration: false, // File will expire (default behavior)
526
+ expirationDays: 7, // Custom expiration in days
527
+ locale: {
528
+ uploadFileErrorMessage: "Failed to upload file. Please try again." // You can optionally provide localized error messages
529
+ }
530
+ });
531
+
532
+ if (uploadWithOptions.success) {
533
+ // The file is now ready to be used in the execution
534
+ const response = await activity.execute();
535
+ console.log(response.content);
536
+ }
537
+
538
+ // Check file status by ID
539
+ const fileStatus = await activity.volatileKnowledge.getById(uploadResult.id);
540
+
541
+ if (fileStatus.success) {
542
+ console.log(
543
+ fileStatus.status, // "analyzing", "invalid", "success", "error", or "expired"
544
+ fileStatus.fileName, // "data.csv"
545
+ fileStatus.fileSize, // Size in bytes
546
+ fileStatus.expirationDate // When the file will be deleted
547
+ );
548
+ } else {
549
+ console.error("Failed to fetch file status:", fileStatus.error);
550
+ }
551
+
552
+ // Remove a specific file from the queue
553
+ const file1 = new File(["content 1"], "data1.csv", { type: "text/csv" });
554
+ const file2 = new File(["content 2"], "data2.csv", { type: "text/csv" });
555
+
556
+ const upload1 = await activity.volatileKnowledge.upload(file1);
557
+ const upload2 = await activity.volatileKnowledge.upload(file2);
558
+
559
+ if (upload1.success && upload2.success) {
560
+ // Remove only the first file
561
+ activity.volatileKnowledge.removeById(upload1.id);
562
+
563
+ // Now only file2 will be included in the next execution
564
+ const response = await activity.execute();
565
+ console.log(response.content);
566
+ }
567
+
568
+ // Clear all files from the queue
569
+ await activity.volatileKnowledge.upload(file1);
570
+ await activity.volatileKnowledge.upload(file2);
571
+
572
+ // Clear all pending files
573
+ activity.volatileKnowledge.clear();
574
+
575
+ // No files will be included in this execution
576
+ const response = await activity.execute();
577
+ ```
578
+
392
579
  ---
393
580
 
394
581
 
@@ -492,6 +679,105 @@ The following options can be passed as the second parameter in `execute` or `cre
492
679
  }
493
680
  ```
494
681
 
682
+ ## Upload Files (volatile knowledge)
683
+
684
+ Upload files to be used as context in your proxy execution. Files are automatically included in the next execution.
685
+
686
+ ```tsx
687
+ import SerenityClient from '@serenity-star/sdk';
688
+
689
+ const client = new SerenityClient({
690
+ apiKey: '<SERENITY_API_KEY>',
691
+ });
692
+
693
+ // Create proxy instance
694
+ const proxy = client.agents.proxies.create("proxy-agent", {
695
+ model: "gpt-4o-mini-2024-07-18",
696
+ messages: [
697
+ { role: "user", content: "Analyze this document" },
698
+ ],
699
+ });
700
+
701
+ // Upload a file
702
+ const file = new File(["content"], "report.pdf", { type: "application/pdf" });
703
+ const uploadResult = await proxy.volatileKnowledge.upload(file);
704
+
705
+ // Check if upload was successful
706
+ if (uploadResult.success) {
707
+ console.log(
708
+ uploadResult.id, // File ID
709
+ uploadResult.fileName, // "report.pdf"
710
+ uploadResult.fileSize, // Size in bytes
711
+ uploadResult.expirationDate, // When the file will be deleted
712
+ uploadResult.status // "analyzing", "invalid", "success", "error", or "expired"
713
+ );
714
+
715
+ // Execute the proxy - the uploaded file will be automatically included
716
+ const response = await proxy.execute();
717
+ console.log(response.content); // Analysis based on the uploaded file
718
+ } else {
719
+ // Handle upload errors
720
+ console.error("Upload failed:", uploadResult.error);
721
+ }
722
+
723
+ // Upload with options
724
+ const imageFile = new File(["image data"], "diagram.png", { type: "image/png" });
725
+ const uploadWithOptions = await proxy.volatileKnowledge.upload(imageFile, {
726
+ useVision: true, // Enable vision for image files (automatically skips embeddings for images)
727
+ noExpiration: false, // File will expire (default behavior)
728
+ expirationDays: 7, // Custom expiration in days
729
+ locale: {
730
+ uploadFileErrorMessage: "Failed to upload file. Please try again." // You can optionally provide localized error messages
731
+ }
732
+ });
733
+
734
+ if (uploadWithOptions.success) {
735
+ // The file is now ready to be used in the execution
736
+ const response = await proxy.execute();
737
+ console.log(response.content);
738
+ }
739
+
740
+ // Check file status by ID
741
+ const fileStatus = await proxy.volatileKnowledge.getById(uploadResult.id);
742
+
743
+ if (fileStatus.success) {
744
+ console.log(
745
+ fileStatus.status, // "analyzing", "invalid", "success", "error", or "expired"
746
+ fileStatus.fileName, // "report.pdf"
747
+ fileStatus.fileSize, // Size in bytes
748
+ fileStatus.expirationDate // When the file will be deleted
749
+ );
750
+ } else {
751
+ console.error("Failed to fetch file status:", fileStatus.error);
752
+ }
753
+
754
+ // Remove a specific file from the queue
755
+ const file1 = new File(["content 1"], "report1.pdf", { type: "application/pdf" });
756
+ const file2 = new File(["content 2"], "report2.pdf", { type: "application/pdf" });
757
+
758
+ const upload1 = await proxy.volatileKnowledge.upload(file1);
759
+ const upload2 = await proxy.volatileKnowledge.upload(file2);
760
+
761
+ if (upload1.success && upload2.success) {
762
+ // Remove only the first file
763
+ proxy.volatileKnowledge.removeById(upload1.id);
764
+
765
+ // Now only file2 will be included in the next execution
766
+ const response = await proxy.execute();
767
+ console.log(response.content);
768
+ }
769
+
770
+ // Clear all files from the queue
771
+ await proxy.volatileKnowledge.upload(file1);
772
+ await proxy.volatileKnowledge.upload(file2);
773
+
774
+ // Clear all pending files
775
+ proxy.volatileKnowledge.clear();
776
+
777
+ // No files will be included in this execution
778
+ const response = await proxy.execute();
779
+ ```
780
+
495
781
  ---
496
782
 
497
783
 
@@ -569,4 +855,100 @@ console.log(
569
855
  response.content, // AI-generated response
570
856
  response.completion_usage // { completion_tokens: 200, prompt_tokens: 30, total_tokens: 230 }
571
857
  );
858
+ ```
859
+
860
+ ## Upload Files (volatile knowledge)
861
+
862
+ Upload files to be used as context in your chat completion execution. Files are automatically included in the next execution.
863
+
864
+ ```tsx
865
+ import SerenityClient from '@serenity-star/sdk';
866
+
867
+ const client = new SerenityClient({
868
+ apiKey: '<SERENITY_API_KEY>',
869
+ });
870
+
871
+ // Create chat completion instance
872
+ const chatCompletion = client.agents.chatCompletions.create("document-assistant", {
873
+ message: "Summarize this document"
874
+ });
875
+
876
+ // Upload a file
877
+ const file = new File(["content"], "document.pdf", { type: "application/pdf" });
878
+ const uploadResult = await chatCompletion.volatileKnowledge.upload(file);
879
+
880
+ // Check if upload was successful
881
+ if (uploadResult.success) {
882
+ console.log(
883
+ uploadResult.id, // File ID
884
+ uploadResult.fileName, // "document.pdf"
885
+ uploadResult.fileSize, // Size in bytes
886
+ uploadResult.expirationDate, // When the file will be deleted
887
+ uploadResult.status // "analyzing", "invalid", "success", "error", or "expired"
888
+ );
889
+
890
+ // Execute the chat completion - the uploaded file will be automatically included
891
+ const response = await chatCompletion.execute();
892
+ console.log(response.content); // Summary based on the uploaded file
893
+ } else {
894
+ // Handle upload errors
895
+ console.error("Upload failed:", uploadResult.error);
896
+ }
897
+
898
+ // Upload with options
899
+ const imageFile = new File(["image data"], "screenshot.png", { type: "image/png" });
900
+ const uploadWithOptions = await chatCompletion.volatileKnowledge.upload(imageFile, {
901
+ useVision: true, // Enable vision for image files (automatically skips embeddings for images)
902
+ noExpiration: false, // File will expire (default behavior)
903
+ expirationDays: 7, // Custom expiration in days
904
+ locale: {
905
+ uploadFileErrorMessage: "Failed to upload file. Please try again." // You can optionally provide localized error messages
906
+ }
907
+ });
908
+
909
+ if (uploadWithOptions.success) {
910
+ // The file is now ready to be used in the execution
911
+ const response = await chatCompletion.execute();
912
+ console.log(response.content);
913
+ }
914
+
915
+ // Check file status by ID
916
+ const fileStatus = await chatCompletion.volatileKnowledge.getById(uploadResult.id);
917
+
918
+ if (fileStatus.success) {
919
+ console.log(
920
+ fileStatus.status, // "analyzing", "invalid", "success", "error", or "expired"
921
+ fileStatus.fileName, // "document.pdf"
922
+ fileStatus.fileSize, // Size in bytes
923
+ fileStatus.expirationDate // When the file will be deleted
924
+ );
925
+ } else {
926
+ console.error("Failed to fetch file status:", fileStatus.error);
927
+ }
928
+
929
+ // Remove a specific file from the queue
930
+ const file1 = new File(["content 1"], "doc1.pdf", { type: "application/pdf" });
931
+ const file2 = new File(["content 2"], "doc2.pdf", { type: "application/pdf" });
932
+
933
+ const upload1 = await chatCompletion.volatileKnowledge.upload(file1);
934
+ const upload2 = await chatCompletion.volatileKnowledge.upload(file2);
935
+
936
+ if (upload1.success && upload2.success) {
937
+ // Remove only the first file
938
+ chatCompletion.volatileKnowledge.removeById(upload1.id);
939
+
940
+ // Now only file2 will be included in the next execution
941
+ const response = await chatCompletion.execute();
942
+ console.log(response.content);
943
+ }
944
+
945
+ // Clear all files from the queue
946
+ await chatCompletion.volatileKnowledge.upload(file1);
947
+ await chatCompletion.volatileKnowledge.upload(file2);
948
+
949
+ // Clear all pending files
950
+ chatCompletion.volatileKnowledge.clear();
951
+
952
+ // No files will be included in this execution
953
+ const response = await chatCompletion.execute();
572
954
  ```