@animaapp/anima-sdk 0.6.17 → 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 +184 -46
- package/dist/index.js +588 -523
- 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, {
|
|
@@ -106,6 +139,8 @@ export declare type CodegenSettings = {
|
|
|
106
139
|
enableDisplayScreenModelId?: boolean;
|
|
107
140
|
enableGeneratePackageLock?: boolean;
|
|
108
141
|
enableAnimationsPreset?: boolean;
|
|
142
|
+
enableDisplayDataId?: boolean;
|
|
143
|
+
enableDisplayDataName?: boolean;
|
|
109
144
|
url?: string;
|
|
110
145
|
codegenSettings?: Record<string, unknown>;
|
|
111
146
|
};
|
|
@@ -115,6 +150,30 @@ export declare type CodegenSettings = {
|
|
|
115
150
|
*/
|
|
116
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";
|
|
117
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
|
+
|
|
118
177
|
/**
|
|
119
178
|
* Creates a Server-Sent Events (SSE) `Response` that forwards all messages from the code generation from website stream.
|
|
120
179
|
*
|
|
@@ -230,6 +289,51 @@ export declare type GeneratingCodePayload = {
|
|
|
230
289
|
files: AnimaFiles;
|
|
231
290
|
};
|
|
232
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
|
+
|
|
233
337
|
/**
|
|
234
338
|
* Errors from the Website To Code Flow
|
|
235
339
|
*/
|
|
@@ -256,7 +360,8 @@ export declare type GetCodeFromWebsiteHandler = ((message: SSEGetCodeFromWebsite
|
|
|
256
360
|
};
|
|
257
361
|
|
|
258
362
|
export declare type GetCodeFromWebsiteParams = {
|
|
259
|
-
url
|
|
363
|
+
url?: string;
|
|
364
|
+
mhtml?: string;
|
|
260
365
|
assetsStorage?: AssetsStorage;
|
|
261
366
|
settings: GetCodeFromWebsiteSettings;
|
|
262
367
|
tracking?: TrackingInfos;
|
|
@@ -270,7 +375,7 @@ export declare type GetCodeFromWebsiteSettings = {
|
|
|
270
375
|
uiLibrary?: "shadcn";
|
|
271
376
|
};
|
|
272
377
|
|
|
273
|
-
export declare type GetCodeHandler = ((message:
|
|
378
|
+
export declare type GetCodeHandler = ((message: SSEGetCodeFromFigmaMessage) => void) | {
|
|
274
379
|
onQueueing?: () => void;
|
|
275
380
|
onStart?: ({ sessionId }: {
|
|
276
381
|
sessionId: string;
|
|
@@ -464,7 +569,7 @@ export declare type L2CParamsStyling = 'tailwind' | 'inline-styles';
|
|
|
464
569
|
* @deprecated This type is deprecated and will be removed soon.
|
|
465
570
|
*/
|
|
466
571
|
export declare type L2CParamsUrlInput = {
|
|
467
|
-
type:
|
|
572
|
+
type: "url";
|
|
468
573
|
url: string;
|
|
469
574
|
};
|
|
470
575
|
|
|
@@ -476,6 +581,14 @@ export declare class NotFound extends Error {
|
|
|
476
581
|
});
|
|
477
582
|
}
|
|
478
583
|
|
|
584
|
+
export declare type ProgressMessage = {
|
|
585
|
+
id: string;
|
|
586
|
+
text: string;
|
|
587
|
+
attachments?: {
|
|
588
|
+
images?: string[];
|
|
589
|
+
};
|
|
590
|
+
};
|
|
591
|
+
|
|
479
592
|
export declare class RateLimitExceeded extends Error {
|
|
480
593
|
fileKey: string;
|
|
481
594
|
constructor({ fileKey, cause }: {
|
|
@@ -500,32 +613,49 @@ export declare class ResponseError extends Error {
|
|
|
500
613
|
/**
|
|
501
614
|
* Errors from the SDK
|
|
502
615
|
*/
|
|
503
|
-
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;
|
|
622
|
+
|
|
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
|
+
};
|
|
504
633
|
|
|
505
|
-
export declare type
|
|
634
|
+
export declare type SSEErrorPayload<Reason> = {
|
|
506
635
|
errorName: string;
|
|
507
636
|
task?: string;
|
|
508
|
-
reason:
|
|
637
|
+
reason: Reason;
|
|
509
638
|
sentryTraceId?: string;
|
|
510
639
|
};
|
|
511
640
|
|
|
512
|
-
export declare type
|
|
513
|
-
type: "queueing";
|
|
514
|
-
} | {
|
|
641
|
+
export declare type SSEGetCodeFromFigmaMessage = SSECommonMessage | {
|
|
515
642
|
type: "start";
|
|
516
643
|
sessionId: string;
|
|
517
|
-
} | {
|
|
518
|
-
type: "pre_codegen";
|
|
519
|
-
message: string;
|
|
520
644
|
} | {
|
|
521
645
|
type: "figma_metadata";
|
|
522
646
|
figmaFileName: string;
|
|
523
647
|
figmaSelectedFrameName: string;
|
|
648
|
+
} | {
|
|
649
|
+
type: "pre_codegen";
|
|
650
|
+
message: string;
|
|
524
651
|
} | {
|
|
525
652
|
type: "generating_code";
|
|
526
653
|
payload: GeneratingCodePayload;
|
|
527
654
|
} | {
|
|
528
655
|
type: "codegen_completed";
|
|
656
|
+
} | {
|
|
657
|
+
type: "post_codegen";
|
|
658
|
+
message: string;
|
|
529
659
|
} | {
|
|
530
660
|
type: "assets_uploaded";
|
|
531
661
|
} | {
|
|
@@ -536,11 +666,9 @@ export declare type SSECodgenMessage = {
|
|
|
536
666
|
url: string;
|
|
537
667
|
}>;
|
|
538
668
|
};
|
|
539
|
-
} | {
|
|
540
|
-
type: "aborted";
|
|
541
669
|
} | {
|
|
542
670
|
type: "error";
|
|
543
|
-
payload:
|
|
671
|
+
payload: SSEGetCodeFromFigmaMessageErrorPayload;
|
|
544
672
|
} | {
|
|
545
673
|
type: "done";
|
|
546
674
|
payload: {
|
|
@@ -549,26 +677,41 @@ export declare type SSECodgenMessage = {
|
|
|
549
677
|
};
|
|
550
678
|
};
|
|
551
679
|
|
|
552
|
-
export declare type
|
|
553
|
-
errorName: string;
|
|
554
|
-
task?: string;
|
|
555
|
-
reason: CodegenErrorReason;
|
|
556
|
-
};
|
|
680
|
+
export declare type SSEGetCodeFromFigmaMessageErrorPayload = SSEErrorPayload<GetCodeFromFigmaErrorReason>;
|
|
557
681
|
|
|
558
|
-
export declare type
|
|
559
|
-
type:
|
|
682
|
+
export declare type SSEGetCodeFromPromptMessage = SSECommonMessage | {
|
|
683
|
+
type: "start";
|
|
684
|
+
sessionId: string;
|
|
560
685
|
} | {
|
|
561
|
-
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";
|
|
562
702
|
sessionId: string;
|
|
563
703
|
} | {
|
|
564
|
-
type:
|
|
704
|
+
type: "generating_code";
|
|
565
705
|
payload: GeneratingCodePayload;
|
|
566
706
|
} | {
|
|
567
|
-
type:
|
|
707
|
+
type: "generation_completed";
|
|
568
708
|
} | {
|
|
569
|
-
type:
|
|
709
|
+
type: "post_codegen";
|
|
710
|
+
message: string;
|
|
570
711
|
} | {
|
|
571
|
-
type:
|
|
712
|
+
type: "assets_uploaded";
|
|
713
|
+
} | {
|
|
714
|
+
type: "assets_list";
|
|
572
715
|
payload: {
|
|
573
716
|
assets: Array<{
|
|
574
717
|
name: string;
|
|
@@ -576,43 +719,38 @@ export declare type SSEGetCodeFromWebsiteMessage = {
|
|
|
576
719
|
}>;
|
|
577
720
|
};
|
|
578
721
|
} | {
|
|
579
|
-
type:
|
|
580
|
-
} | {
|
|
581
|
-
type: 'error';
|
|
722
|
+
type: "error";
|
|
582
723
|
payload: SSEGetCodeFromWebsiteMessageErrorPayload;
|
|
583
724
|
} | {
|
|
584
|
-
type:
|
|
725
|
+
type: "done";
|
|
585
726
|
payload: {
|
|
586
727
|
sessionId: string;
|
|
587
728
|
tokenUsage: number;
|
|
588
729
|
};
|
|
589
730
|
};
|
|
590
731
|
|
|
591
|
-
export declare type SSEGetCodeFromWebsiteMessageErrorPayload =
|
|
592
|
-
errorName: string;
|
|
593
|
-
task?: string;
|
|
594
|
-
reason: GetCodeFromWebsiteErrorReason;
|
|
595
|
-
sentryTraceId?: string;
|
|
596
|
-
};
|
|
732
|
+
export declare type SSEGetCodeFromWebsiteMessageErrorPayload = SSEErrorPayload<GetCodeFromWebsiteErrorReason>;
|
|
597
733
|
|
|
598
734
|
/**
|
|
599
735
|
* @deprecated This type is deprecated and will be removed soon.
|
|
600
736
|
*/
|
|
601
737
|
export declare type SSEL2CMessage = SSEGetCodeFromWebsiteMessage;
|
|
602
738
|
|
|
739
|
+
export declare type StreamCodeFromPromptMessage = StreamMessage<SSEGetCodeFromPromptMessage>;
|
|
740
|
+
|
|
603
741
|
export declare type StreamCodeFromWebsiteMessage = StreamMessage<SSEGetCodeFromWebsiteMessage>;
|
|
604
742
|
|
|
605
|
-
export declare type StreamCodgenMessage = StreamMessage<
|
|
743
|
+
export declare type StreamCodgenMessage = StreamMessage<SSEGetCodeFromFigmaMessage>;
|
|
606
744
|
|
|
607
745
|
declare type StreamErrorPayload = {
|
|
608
746
|
name: string;
|
|
609
|
-
message:
|
|
747
|
+
message: GetCodeFromFigmaErrorReason;
|
|
610
748
|
status?: number;
|
|
611
749
|
detail?: unknown;
|
|
612
|
-
errorPayload?:
|
|
750
|
+
errorPayload?: SSEGetCodeFromFigmaMessageErrorPayload;
|
|
613
751
|
};
|
|
614
752
|
|
|
615
|
-
export declare type StreamL2CMessage = StreamMessage<
|
|
753
|
+
export declare type StreamL2CMessage = StreamMessage<SSEGetCodeFromWebsiteMessage>;
|
|
616
754
|
|
|
617
755
|
export declare type StreamMessage<T> = Exclude<T, {
|
|
618
756
|
type: "error";
|