@animaapp/anima-sdk 0.11.0 → 0.13.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/dist/index.d.ts CHANGED
@@ -51,7 +51,8 @@ export declare class Anima {
51
51
  /**
52
52
  * @deprecated This method will be removed soon, please use `generateCodeFromWebsite` instead.
53
53
  */
54
- generateLink2Code(params: GetLink2CodeParams, handler?: GetLink2CodeHandler, signal?: AbortSignal): Promise<AnimaSDKResult>;
54
+ generateLink2Code(params: GetLink2CodeParams, handler?: GetCodeFromWebsiteHandler, signal?: AbortSignal): Promise<AnimaSDKResult>;
55
+ attachToGenerationJob<T extends SSEGetCodeFromFigmaMessage | SSEGetCodeFromWebsiteMessage | SSEGetCodeFromPromptMessage>(params: AttachToGenerationJobParams, handler?: ((message: T) => void) | Record<string, any>, signal?: AbortSignal): Promise<AnimaSDKResult>;
55
56
  }
56
57
 
57
58
  export declare type AnimaFiles = Record<string, {
@@ -74,6 +75,32 @@ export declare type AssetsStorage = {
74
75
  url: string;
75
76
  };
76
77
 
78
+ export declare type AttachToGenerationJobParams = {
79
+ sessionId: string;
80
+ };
81
+
82
+ /**
83
+ * Creates a Server-Sent Events (SSE) `Response` that forwards all messages from the code generation stream.
84
+ *
85
+ * But, if the first message indicates an error (e.g., connection failed), the function returns a 500 response with the error message.
86
+ *
87
+ * @param {Anima} anima - The Anima instance to use for creating the data stream.
88
+ * @param {GetCodeFromPromptParams} params - The parameters for the code generation request.
89
+ * @returns {Promise<Response>} - A promise that resolves to an HTTP response.
90
+ */
91
+ export declare const attachToGenerationJobResponseEventStream: (anima: Anima, params: AttachToGenerationJobParams) => Promise<Response>;
92
+
93
+ /**
94
+ * Creates a ReadableStream to output code generation result.
95
+ *
96
+ * The stream is closed when the code generation ends.
97
+ *
98
+ * @param {Anima} anima - An Anima service instance to generate the code from.
99
+ * @param {GetCodeFromPromptParams} params - Parameters required for the code generation process.
100
+ * @returns {ReadableStream<StreamCodeFromPromptMessage>} - A ReadableStream that emits messages related to the code generation process.
101
+ */
102
+ export declare const attachToGenerationJobStream: (anima: Anima, params: AttachToGenerationJobParams) => ReadableStream<StreamCodgenMessage | StreamCodeFromWebsiteMessage | StreamCodeFromPromptMessage>;
103
+
77
104
  export declare type Auth = {
78
105
  token: string;
79
106
  teamId: string;
@@ -153,7 +180,7 @@ export declare type CodegenSettings = BaseSettings & {
153
180
  /**
154
181
  * Errors from Anima API, common across multiple routes.
155
182
  */
156
- export declare type CommonApiError = "Missing Authorization header" | "Invalid Authorization header" | "Missing teamId" | "Internal server error" | "Forbidden, no team access" | "Requested Usage Exceeds Limit" | "Too many concurrent jobs" | "Invalid Anima token";
183
+ export declare type CommonApiError = "Missing Authorization header" | "Invalid Authorization header" | "Missing teamId" | "Internal server error" | "Forbidden, no team access" | "Requested Usage Exceeds Limit" | "Too many concurrent jobs" | "Invalid Anima token" | "Job not found";
157
184
 
158
185
  /**
159
186
  * Creates a Server-Sent Events (SSE) `Response` that forwards all messages from the code generation from prompt stream.
@@ -496,6 +523,8 @@ export declare const isUnknownFigmaApiException: (error: Error) => boolean;
496
523
 
497
524
  export declare const isValidFigmaUrl: (figmaLink: string) => [hasCorrectPrefix: boolean, fileKey: string, nodeId: string];
498
525
 
526
+ export declare type JobType = "f2c" | "l2c" | "p2c";
527
+
499
528
  /**
500
529
  * @deprecated This type is deprecated and will be removed soon.
501
530
  */
@@ -643,7 +672,7 @@ export declare type SDKErrorReason = "Invalid body payload" | "Connection closed
643
672
  */
644
673
  export declare type SSECodegenMessage = SSEGetCodeFromFigmaMessage;
645
674
 
646
- export declare type SSECommonMessage = {
675
+ export declare type SSECommonMessage<TErrorReason extends string = string> = {
647
676
  type: "queueing";
648
677
  payload: {
649
678
  sessionId: string;
@@ -652,14 +681,30 @@ export declare type SSECommonMessage = {
652
681
  type: "progress_messages_updated";
653
682
  payload: {
654
683
  progressMessages: ProgressMessage[];
684
+ jobType?: string | null;
655
685
  };
656
686
  } | {
657
687
  type: "job_status_updated";
658
688
  payload: {
659
689
  jobStatus: Record<string, any>;
690
+ jobType?: string | null;
660
691
  };
661
692
  } | {
662
693
  type: "aborted";
694
+ } | {
695
+ type: "done";
696
+ payload: {
697
+ sessionId: string;
698
+ tokenUsage: number;
699
+ };
700
+ } | {
701
+ type: "error";
702
+ payload: SSEErrorPayload<TErrorReason>;
703
+ } | {
704
+ type: "set_job_type";
705
+ payload: {
706
+ jobType: JobType;
707
+ };
663
708
  };
664
709
 
665
710
  export declare type SSEErrorPayload<Reason> = {
@@ -669,7 +714,7 @@ export declare type SSEErrorPayload<Reason> = {
669
714
  sentryTraceId?: string;
670
715
  };
671
716
 
672
- export declare type SSEGetCodeFromFigmaMessage = SSECommonMessage | {
717
+ export declare type SSEGetCodeFromFigmaMessage = SSECommonMessage<GetCodeFromFigmaErrorReason> | {
673
718
  type: "start";
674
719
  sessionId: string;
675
720
  } | {
@@ -697,38 +742,20 @@ export declare type SSEGetCodeFromFigmaMessage = SSECommonMessage | {
697
742
  url: string;
698
743
  }>;
699
744
  };
700
- } | {
701
- type: "error";
702
- payload: SSEGetCodeFromFigmaMessageErrorPayload;
703
- } | {
704
- type: "done";
705
- payload: {
706
- sessionId: string;
707
- tokenUsage: number;
708
- };
709
745
  };
710
746
 
711
747
  export declare type SSEGetCodeFromFigmaMessageErrorPayload = SSEErrorPayload<GetCodeFromFigmaErrorReason>;
712
748
 
713
- export declare type SSEGetCodeFromPromptMessage = SSECommonMessage | {
749
+ export declare type SSEGetCodeFromPromptMessage = SSECommonMessage<GetCodeFromPromptErrorReason> | {
714
750
  type: "start";
715
751
  sessionId: string;
716
752
  } | {
717
753
  type: "generation_completed";
718
- } | {
719
- type: "error";
720
- payload: SSEGetCodeFromPromptMessageErrorPayload;
721
- } | {
722
- type: "done";
723
- payload: {
724
- sessionId: string;
725
- tokenUsage: number;
726
- };
727
754
  };
728
755
 
729
756
  export declare type SSEGetCodeFromPromptMessageErrorPayload = SSEErrorPayload<GetCodeFromPromptErrorReason>;
730
757
 
731
- export declare type SSEGetCodeFromWebsiteMessage = SSECommonMessage | {
758
+ export declare type SSEGetCodeFromWebsiteMessage = SSECommonMessage<GetCodeFromWebsiteErrorReason> | {
732
759
  type: "start";
733
760
  sessionId: string;
734
761
  } | {
@@ -749,15 +776,6 @@ export declare type SSEGetCodeFromWebsiteMessage = SSECommonMessage | {
749
776
  url: string;
750
777
  }>;
751
778
  };
752
- } | {
753
- type: "error";
754
- payload: SSEGetCodeFromWebsiteMessageErrorPayload;
755
- } | {
756
- type: "done";
757
- payload: {
758
- sessionId: string;
759
- tokenUsage: number;
760
- };
761
779
  };
762
780
 
763
781
  export declare type SSEGetCodeFromWebsiteMessageErrorPayload = SSEErrorPayload<GetCodeFromWebsiteErrorReason>;