@animaapp/anima-sdk 0.6.18 → 0.6.20
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.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +180 -45
- package/dist/index.js +546 -496
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,39 @@ export declare class Anima {
|
|
|
17
17
|
protected get headers(): Record<string, string>;
|
|
18
18
|
generateCode(params: GetCodeParams, handler?: GetCodeHandler, signal?: AbortSignal): Promise<AnimaSDKResult>;
|
|
19
19
|
generateCodeFromWebsite(params: GetCodeFromWebsiteParams, handler?: GetCodeFromWebsiteHandler, signal?: AbortSignal): Promise<AnimaSDKResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Generates code from a text prompt using AI.
|
|
22
|
+
*
|
|
23
|
+
* This method sends a prompt to the Anima API and generates code based on the description provided.
|
|
24
|
+
* It supports real-time streaming of the generation process through Server-Sent Events (SSE).
|
|
25
|
+
*
|
|
26
|
+
* @param params - The parameters for code generation
|
|
27
|
+
* @param params.prompt - The text prompt describing what code to generate
|
|
28
|
+
* @param params.settings - Code generation settings (framework, language, styling, etc.)
|
|
29
|
+
* @param params.assetsStorage - Optional asset storage configuration
|
|
30
|
+
* @param params.tracking - Optional tracking information
|
|
31
|
+
* @param params.webhookUrl - Optional webhook URL for completion notification
|
|
32
|
+
* @param handler - Event handler for processing SSE messages during generation
|
|
33
|
+
* @param signal - Optional AbortSignal to cancel the request
|
|
34
|
+
* @returns Promise resolving to AnimaSDKResult with generated files and metadata
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const result = await anima.generateCodeFromPrompt({
|
|
39
|
+
* prompt: "Create a login form with email and password fields",
|
|
40
|
+
* settings: {
|
|
41
|
+
* framework: "react",
|
|
42
|
+
* language: "typescript",
|
|
43
|
+
* styling: "tailwind"
|
|
44
|
+
* }
|
|
45
|
+
* }, {
|
|
46
|
+
* onStart: ({ sessionId }) => console.log("Started:", sessionId),
|
|
47
|
+
* onGeneratingCode: ({ progress }) => console.log("Progress:", progress),
|
|
48
|
+
* onCodegenCompleted: () => console.log("Generation completed!")
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
generateCodeFromPrompt(params: GetCodeFromPromptParams, handler?: GetCodeFromPromptHandler, signal?: AbortSignal): Promise<AnimaSDKResult>;
|
|
20
53
|
/**
|
|
21
54
|
* @deprecated This method will be removed soon, please use `generateCodeFromWebsite` instead.
|
|
22
55
|
*/
|
|
@@ -53,8 +86,8 @@ export declare type Auth = {
|
|
|
53
86
|
|
|
54
87
|
export declare type BaseResult = {
|
|
55
88
|
sessionId: string;
|
|
56
|
-
figmaFileName
|
|
57
|
-
figmaSelectedFrameName
|
|
89
|
+
figmaFileName?: string;
|
|
90
|
+
figmaSelectedFrameName?: string;
|
|
58
91
|
tokenUsage: number;
|
|
59
92
|
};
|
|
60
93
|
|
|
@@ -63,16 +96,16 @@ export declare class CodegenError extends Error {
|
|
|
63
96
|
detail?: unknown;
|
|
64
97
|
constructor({ name, reason, status, detail, }: {
|
|
65
98
|
name: string;
|
|
66
|
-
reason: CommonApiError |
|
|
99
|
+
reason: CommonApiError | GetCodeFromFigmaErrorReason | CodegenRouteErrorReason | SDKErrorReason | GetCodeFromWebsiteErrorReason | GetCodeFromPromptErrorReason;
|
|
67
100
|
status?: number;
|
|
68
101
|
detail?: unknown;
|
|
69
102
|
});
|
|
70
103
|
}
|
|
71
104
|
|
|
72
105
|
/**
|
|
73
|
-
*
|
|
106
|
+
* @deprecated This type is deprecated and will be removed soon.
|
|
74
107
|
*/
|
|
75
|
-
export declare type CodegenErrorReason =
|
|
108
|
+
export declare type CodegenErrorReason = GetCodeFromFigmaErrorReason;
|
|
76
109
|
|
|
77
110
|
export declare type CodegenResult = BaseResult & {
|
|
78
111
|
files: Record<string, {
|
|
@@ -117,6 +150,30 @@ export declare type CodegenSettings = {
|
|
|
117
150
|
*/
|
|
118
151
|
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";
|
|
119
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Creates a Server-Sent Events (SSE) `Response` that forwards all messages from the code generation from prompt stream.
|
|
155
|
+
*
|
|
156
|
+
* But, if the first message indicates an error (e.g., connection failed), the function returns a 500 response with the error message.
|
|
157
|
+
*
|
|
158
|
+
* @param {Anima} anima - The Anima instance to use for creating the data stream.
|
|
159
|
+
* @param {GetCodeFromPromptParams} params - The parameters for the code generation request.
|
|
160
|
+
* @returns {Promise<Response>} - A promise that resolves to an HTTP response.
|
|
161
|
+
*/
|
|
162
|
+
export declare const createCodeFromPromptResponseEventStream: (anima: Anima, params: GetCodeFromPromptParams) => Promise<Response>;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Prompt to Code (p2c) stream flow.
|
|
166
|
+
*
|
|
167
|
+
* Start the prompt to code generation and creates a ReadableStream to output its result.
|
|
168
|
+
*
|
|
169
|
+
* The stream is closed when the code generation ends.
|
|
170
|
+
*
|
|
171
|
+
* @param {Anima} anima - An Anima service instance to generate the code from.
|
|
172
|
+
* @param {GetCodeFromPromptParams} params - Parameters required for the code generation process.
|
|
173
|
+
* @returns {ReadableStream<StreamCodeFromPromptMessage>} - A ReadableStream that emits messages related to the code generation process.
|
|
174
|
+
*/
|
|
175
|
+
export declare const createCodeFromPromptStream: (anima: Anima, params: GetCodeFromPromptParams) => ReadableStream<StreamCodeFromPromptMessage>;
|
|
176
|
+
|
|
120
177
|
/**
|
|
121
178
|
* Creates a Server-Sent Events (SSE) `Response` that forwards all messages from the code generation from website stream.
|
|
122
179
|
*
|
|
@@ -232,6 +289,51 @@ export declare type GeneratingCodePayload = {
|
|
|
232
289
|
files: AnimaFiles;
|
|
233
290
|
};
|
|
234
291
|
|
|
292
|
+
/**
|
|
293
|
+
* Codegen errors from the worker
|
|
294
|
+
*/
|
|
295
|
+
export declare type GetCodeFromFigmaErrorReason = "Selected node type is not supported" | "Invisible group nodes are unsupported" | "Selected node is a page with multiple children" | "Selected node is a page with no valid children" | "There is no node with the given id" | "Invalid Figma token" | "Anima API connection error" | "Figma token expired" | "Invalid user token" | "Figma file not found" | "Figma rate limit exceeded" | "Figma selection too large" | "Invalid responsive page node type" | "Unknown";
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Errors from the Prompt To Code Flow
|
|
299
|
+
*/
|
|
300
|
+
export declare type GetCodeFromPromptErrorReason = "Invalid prompt" | "Generation failed" | "Unknown";
|
|
301
|
+
|
|
302
|
+
export declare type GetCodeFromPromptHandler = ((message: SSEGetCodeFromPromptMessage) => void) | {
|
|
303
|
+
onQueueing?: () => void;
|
|
304
|
+
onStart?: ({ sessionId }: {
|
|
305
|
+
sessionId: string;
|
|
306
|
+
}) => void;
|
|
307
|
+
onAssetsUploaded?: () => void;
|
|
308
|
+
onAssetsList?: ({ assets, }: {
|
|
309
|
+
assets: Array<{
|
|
310
|
+
name: string;
|
|
311
|
+
url: string;
|
|
312
|
+
}>;
|
|
313
|
+
}) => void;
|
|
314
|
+
onGeneratingCode?: ({ status, progress, files, }: {
|
|
315
|
+
status: "success" | "running" | "failure";
|
|
316
|
+
progress: number;
|
|
317
|
+
files: AnimaFiles;
|
|
318
|
+
}) => void;
|
|
319
|
+
onCodegenCompleted?: () => void;
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
export declare type GetCodeFromPromptParams = {
|
|
323
|
+
prompt: string;
|
|
324
|
+
assetsStorage?: AssetsStorage;
|
|
325
|
+
settings: GetCodeFromPromptSettings;
|
|
326
|
+
tracking?: TrackingInfos;
|
|
327
|
+
webhookUrl?: string;
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
export declare type GetCodeFromPromptSettings = {
|
|
331
|
+
language?: "typescript";
|
|
332
|
+
framework: "react" | "html";
|
|
333
|
+
styling: "tailwind" | "inline_styles";
|
|
334
|
+
uiLibrary?: "shadcn";
|
|
335
|
+
};
|
|
336
|
+
|
|
235
337
|
/**
|
|
236
338
|
* Errors from the Website To Code Flow
|
|
237
339
|
*/
|
|
@@ -273,7 +375,7 @@ export declare type GetCodeFromWebsiteSettings = {
|
|
|
273
375
|
uiLibrary?: "shadcn";
|
|
274
376
|
};
|
|
275
377
|
|
|
276
|
-
export declare type GetCodeHandler = ((message:
|
|
378
|
+
export declare type GetCodeHandler = ((message: SSEGetCodeFromFigmaMessage) => void) | {
|
|
277
379
|
onQueueing?: () => void;
|
|
278
380
|
onStart?: ({ sessionId }: {
|
|
279
381
|
sessionId: string;
|
|
@@ -467,7 +569,7 @@ export declare type L2CParamsStyling = 'tailwind' | 'inline-styles';
|
|
|
467
569
|
* @deprecated This type is deprecated and will be removed soon.
|
|
468
570
|
*/
|
|
469
571
|
export declare type L2CParamsUrlInput = {
|
|
470
|
-
type:
|
|
572
|
+
type: "url";
|
|
471
573
|
url: string;
|
|
472
574
|
};
|
|
473
575
|
|
|
@@ -479,6 +581,14 @@ export declare class NotFound extends Error {
|
|
|
479
581
|
});
|
|
480
582
|
}
|
|
481
583
|
|
|
584
|
+
export declare type ProgressMessage = {
|
|
585
|
+
id: string;
|
|
586
|
+
text: string;
|
|
587
|
+
attachments?: {
|
|
588
|
+
images?: string[];
|
|
589
|
+
};
|
|
590
|
+
};
|
|
591
|
+
|
|
482
592
|
export declare class RateLimitExceeded extends Error {
|
|
483
593
|
fileKey: string;
|
|
484
594
|
constructor({ fileKey, cause }: {
|
|
@@ -503,32 +613,49 @@ export declare class ResponseError extends Error {
|
|
|
503
613
|
/**
|
|
504
614
|
* Errors from the SDK
|
|
505
615
|
*/
|
|
506
|
-
export declare type SDKErrorReason = "Invalid body payload" | "
|
|
616
|
+
export declare type SDKErrorReason = "Invalid body payload" | "Connection closed before the 'done' message" | "Response body is null";
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* @deprecated This type is deprecated and will be removed soon.
|
|
620
|
+
*/
|
|
621
|
+
export declare type SSECodegenMessage = SSEGetCodeFromFigmaMessage;
|
|
507
622
|
|
|
508
|
-
export declare type
|
|
623
|
+
export declare type SSECommonMessage = {
|
|
624
|
+
type: "queueing";
|
|
625
|
+
} | {
|
|
626
|
+
type: "progress_messages_updated";
|
|
627
|
+
payload: {
|
|
628
|
+
progressMessages: ProgressMessage[];
|
|
629
|
+
};
|
|
630
|
+
} | {
|
|
631
|
+
type: "aborted";
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
export declare type SSEErrorPayload<Reason> = {
|
|
509
635
|
errorName: string;
|
|
510
636
|
task?: string;
|
|
511
|
-
reason:
|
|
637
|
+
reason: Reason;
|
|
512
638
|
sentryTraceId?: string;
|
|
513
639
|
};
|
|
514
640
|
|
|
515
|
-
export declare type
|
|
516
|
-
type: "queueing";
|
|
517
|
-
} | {
|
|
641
|
+
export declare type SSEGetCodeFromFigmaMessage = SSECommonMessage | {
|
|
518
642
|
type: "start";
|
|
519
643
|
sessionId: string;
|
|
520
|
-
} | {
|
|
521
|
-
type: "pre_codegen";
|
|
522
|
-
message: string;
|
|
523
644
|
} | {
|
|
524
645
|
type: "figma_metadata";
|
|
525
646
|
figmaFileName: string;
|
|
526
647
|
figmaSelectedFrameName: string;
|
|
648
|
+
} | {
|
|
649
|
+
type: "pre_codegen";
|
|
650
|
+
message: string;
|
|
527
651
|
} | {
|
|
528
652
|
type: "generating_code";
|
|
529
653
|
payload: GeneratingCodePayload;
|
|
530
654
|
} | {
|
|
531
655
|
type: "codegen_completed";
|
|
656
|
+
} | {
|
|
657
|
+
type: "post_codegen";
|
|
658
|
+
message: string;
|
|
532
659
|
} | {
|
|
533
660
|
type: "assets_uploaded";
|
|
534
661
|
} | {
|
|
@@ -539,11 +666,9 @@ export declare type SSECodgenMessage = {
|
|
|
539
666
|
url: string;
|
|
540
667
|
}>;
|
|
541
668
|
};
|
|
542
|
-
} | {
|
|
543
|
-
type: "aborted";
|
|
544
669
|
} | {
|
|
545
670
|
type: "error";
|
|
546
|
-
payload:
|
|
671
|
+
payload: SSEGetCodeFromFigmaMessageErrorPayload;
|
|
547
672
|
} | {
|
|
548
673
|
type: "done";
|
|
549
674
|
payload: {
|
|
@@ -552,26 +677,41 @@ export declare type SSECodgenMessage = {
|
|
|
552
677
|
};
|
|
553
678
|
};
|
|
554
679
|
|
|
555
|
-
export declare type
|
|
556
|
-
errorName: string;
|
|
557
|
-
task?: string;
|
|
558
|
-
reason: CodegenErrorReason;
|
|
559
|
-
};
|
|
680
|
+
export declare type SSEGetCodeFromFigmaMessageErrorPayload = SSEErrorPayload<GetCodeFromFigmaErrorReason>;
|
|
560
681
|
|
|
561
|
-
export declare type
|
|
562
|
-
type:
|
|
682
|
+
export declare type SSEGetCodeFromPromptMessage = SSECommonMessage | {
|
|
683
|
+
type: "start";
|
|
684
|
+
sessionId: string;
|
|
563
685
|
} | {
|
|
564
|
-
type:
|
|
686
|
+
type: "generation_completed";
|
|
687
|
+
} | {
|
|
688
|
+
type: "error";
|
|
689
|
+
payload: SSEGetCodeFromPromptMessageErrorPayload;
|
|
690
|
+
} | {
|
|
691
|
+
type: "done";
|
|
692
|
+
payload: {
|
|
693
|
+
sessionId: string;
|
|
694
|
+
tokenUsage: number;
|
|
695
|
+
};
|
|
696
|
+
};
|
|
697
|
+
|
|
698
|
+
export declare type SSEGetCodeFromPromptMessageErrorPayload = SSEErrorPayload<GetCodeFromPromptErrorReason>;
|
|
699
|
+
|
|
700
|
+
export declare type SSEGetCodeFromWebsiteMessage = SSECommonMessage | {
|
|
701
|
+
type: "start";
|
|
565
702
|
sessionId: string;
|
|
566
703
|
} | {
|
|
567
|
-
type:
|
|
704
|
+
type: "generating_code";
|
|
568
705
|
payload: GeneratingCodePayload;
|
|
569
706
|
} | {
|
|
570
|
-
type:
|
|
707
|
+
type: "generation_completed";
|
|
571
708
|
} | {
|
|
572
|
-
type:
|
|
709
|
+
type: "post_codegen";
|
|
710
|
+
message: string;
|
|
573
711
|
} | {
|
|
574
|
-
type:
|
|
712
|
+
type: "assets_uploaded";
|
|
713
|
+
} | {
|
|
714
|
+
type: "assets_list";
|
|
575
715
|
payload: {
|
|
576
716
|
assets: Array<{
|
|
577
717
|
name: string;
|
|
@@ -579,43 +719,38 @@ export declare type SSEGetCodeFromWebsiteMessage = {
|
|
|
579
719
|
}>;
|
|
580
720
|
};
|
|
581
721
|
} | {
|
|
582
|
-
type:
|
|
583
|
-
} | {
|
|
584
|
-
type: 'error';
|
|
722
|
+
type: "error";
|
|
585
723
|
payload: SSEGetCodeFromWebsiteMessageErrorPayload;
|
|
586
724
|
} | {
|
|
587
|
-
type:
|
|
725
|
+
type: "done";
|
|
588
726
|
payload: {
|
|
589
727
|
sessionId: string;
|
|
590
728
|
tokenUsage: number;
|
|
591
729
|
};
|
|
592
730
|
};
|
|
593
731
|
|
|
594
|
-
export declare type SSEGetCodeFromWebsiteMessageErrorPayload =
|
|
595
|
-
errorName: string;
|
|
596
|
-
task?: string;
|
|
597
|
-
reason: GetCodeFromWebsiteErrorReason;
|
|
598
|
-
sentryTraceId?: string;
|
|
599
|
-
};
|
|
732
|
+
export declare type SSEGetCodeFromWebsiteMessageErrorPayload = SSEErrorPayload<GetCodeFromWebsiteErrorReason>;
|
|
600
733
|
|
|
601
734
|
/**
|
|
602
735
|
* @deprecated This type is deprecated and will be removed soon.
|
|
603
736
|
*/
|
|
604
737
|
export declare type SSEL2CMessage = SSEGetCodeFromWebsiteMessage;
|
|
605
738
|
|
|
739
|
+
export declare type StreamCodeFromPromptMessage = StreamMessage<SSEGetCodeFromPromptMessage>;
|
|
740
|
+
|
|
606
741
|
export declare type StreamCodeFromWebsiteMessage = StreamMessage<SSEGetCodeFromWebsiteMessage>;
|
|
607
742
|
|
|
608
|
-
export declare type StreamCodgenMessage = StreamMessage<
|
|
743
|
+
export declare type StreamCodgenMessage = StreamMessage<SSEGetCodeFromFigmaMessage>;
|
|
609
744
|
|
|
610
745
|
declare type StreamErrorPayload = {
|
|
611
746
|
name: string;
|
|
612
|
-
message:
|
|
747
|
+
message: GetCodeFromFigmaErrorReason;
|
|
613
748
|
status?: number;
|
|
614
749
|
detail?: unknown;
|
|
615
|
-
errorPayload?:
|
|
750
|
+
errorPayload?: SSEGetCodeFromFigmaMessageErrorPayload;
|
|
616
751
|
};
|
|
617
752
|
|
|
618
|
-
export declare type StreamL2CMessage = StreamMessage<
|
|
753
|
+
export declare type StreamL2CMessage = StreamMessage<SSEGetCodeFromWebsiteMessage>;
|
|
619
754
|
|
|
620
755
|
export declare type StreamMessage<T> = Exclude<T, {
|
|
621
756
|
type: "error";
|