@animaapp/anima-sdk 0.6.18 → 0.6.21
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 +186 -48
- package/dist/index.js +547 -496
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,26 +86,30 @@ 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
|
|
|
94
|
+
export declare type BaseSettings = {
|
|
95
|
+
codegenSettings?: Record<string, unknown>;
|
|
96
|
+
};
|
|
97
|
+
|
|
61
98
|
export declare class CodegenError extends Error {
|
|
62
99
|
status?: number;
|
|
63
100
|
detail?: unknown;
|
|
64
101
|
constructor({ name, reason, status, detail, }: {
|
|
65
102
|
name: string;
|
|
66
|
-
reason: CommonApiError |
|
|
103
|
+
reason: CommonApiError | GetCodeFromFigmaErrorReason | CodegenRouteErrorReason | SDKErrorReason | GetCodeFromWebsiteErrorReason | GetCodeFromPromptErrorReason;
|
|
67
104
|
status?: number;
|
|
68
105
|
detail?: unknown;
|
|
69
106
|
});
|
|
70
107
|
}
|
|
71
108
|
|
|
72
109
|
/**
|
|
73
|
-
*
|
|
110
|
+
* @deprecated This type is deprecated and will be removed soon.
|
|
74
111
|
*/
|
|
75
|
-
export declare type CodegenErrorReason =
|
|
112
|
+
export declare type CodegenErrorReason = GetCodeFromFigmaErrorReason;
|
|
76
113
|
|
|
77
114
|
export declare type CodegenResult = BaseResult & {
|
|
78
115
|
files: Record<string, {
|
|
@@ -86,7 +123,7 @@ export declare type CodegenResult = BaseResult & {
|
|
|
86
123
|
*/
|
|
87
124
|
export declare type CodegenRouteErrorReason = "Not all frames id from responsive pages are mentioned on the nodes id list" | "Too many screens to import";
|
|
88
125
|
|
|
89
|
-
export declare type CodegenSettings = {
|
|
126
|
+
export declare type CodegenSettings = BaseSettings & {
|
|
90
127
|
language?: "typescript" | "javascript";
|
|
91
128
|
model?: string;
|
|
92
129
|
framework: "react" | "html";
|
|
@@ -109,7 +146,6 @@ export declare type CodegenSettings = {
|
|
|
109
146
|
enableDisplayDataId?: boolean;
|
|
110
147
|
enableDisplayDataName?: boolean;
|
|
111
148
|
url?: string;
|
|
112
|
-
codegenSettings?: Record<string, unknown>;
|
|
113
149
|
};
|
|
114
150
|
|
|
115
151
|
/**
|
|
@@ -117,6 +153,30 @@ export declare type CodegenSettings = {
|
|
|
117
153
|
*/
|
|
118
154
|
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
155
|
|
|
156
|
+
/**
|
|
157
|
+
* Creates a Server-Sent Events (SSE) `Response` that forwards all messages from the code generation from prompt stream.
|
|
158
|
+
*
|
|
159
|
+
* But, if the first message indicates an error (e.g., connection failed), the function returns a 500 response with the error message.
|
|
160
|
+
*
|
|
161
|
+
* @param {Anima} anima - The Anima instance to use for creating the data stream.
|
|
162
|
+
* @param {GetCodeFromPromptParams} params - The parameters for the code generation request.
|
|
163
|
+
* @returns {Promise<Response>} - A promise that resolves to an HTTP response.
|
|
164
|
+
*/
|
|
165
|
+
export declare const createCodeFromPromptResponseEventStream: (anima: Anima, params: GetCodeFromPromptParams) => Promise<Response>;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Prompt to Code (p2c) stream flow.
|
|
169
|
+
*
|
|
170
|
+
* Start the prompt to code generation and creates a ReadableStream to output its result.
|
|
171
|
+
*
|
|
172
|
+
* The stream is closed when the code generation ends.
|
|
173
|
+
*
|
|
174
|
+
* @param {Anima} anima - An Anima service instance to generate the code from.
|
|
175
|
+
* @param {GetCodeFromPromptParams} params - Parameters required for the code generation process.
|
|
176
|
+
* @returns {ReadableStream<StreamCodeFromPromptMessage>} - A ReadableStream that emits messages related to the code generation process.
|
|
177
|
+
*/
|
|
178
|
+
export declare const createCodeFromPromptStream: (anima: Anima, params: GetCodeFromPromptParams) => ReadableStream<StreamCodeFromPromptMessage>;
|
|
179
|
+
|
|
120
180
|
/**
|
|
121
181
|
* Creates a Server-Sent Events (SSE) `Response` that forwards all messages from the code generation from website stream.
|
|
122
182
|
*
|
|
@@ -232,6 +292,51 @@ export declare type GeneratingCodePayload = {
|
|
|
232
292
|
files: AnimaFiles;
|
|
233
293
|
};
|
|
234
294
|
|
|
295
|
+
/**
|
|
296
|
+
* Codegen errors from the worker
|
|
297
|
+
*/
|
|
298
|
+
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";
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Errors from the Prompt To Code Flow
|
|
302
|
+
*/
|
|
303
|
+
export declare type GetCodeFromPromptErrorReason = "Invalid prompt" | "Generation failed" | "Unknown";
|
|
304
|
+
|
|
305
|
+
export declare type GetCodeFromPromptHandler = ((message: SSEGetCodeFromPromptMessage) => void) | {
|
|
306
|
+
onQueueing?: () => void;
|
|
307
|
+
onStart?: ({ sessionId }: {
|
|
308
|
+
sessionId: string;
|
|
309
|
+
}) => void;
|
|
310
|
+
onAssetsUploaded?: () => void;
|
|
311
|
+
onAssetsList?: ({ assets, }: {
|
|
312
|
+
assets: Array<{
|
|
313
|
+
name: string;
|
|
314
|
+
url: string;
|
|
315
|
+
}>;
|
|
316
|
+
}) => void;
|
|
317
|
+
onGeneratingCode?: ({ status, progress, files, }: {
|
|
318
|
+
status: "success" | "running" | "failure";
|
|
319
|
+
progress: number;
|
|
320
|
+
files: AnimaFiles;
|
|
321
|
+
}) => void;
|
|
322
|
+
onCodegenCompleted?: () => void;
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
export declare type GetCodeFromPromptParams = {
|
|
326
|
+
prompt: string;
|
|
327
|
+
assetsStorage?: AssetsStorage;
|
|
328
|
+
settings: GetCodeFromPromptSettings;
|
|
329
|
+
tracking?: TrackingInfos;
|
|
330
|
+
webhookUrl?: string;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
export declare type GetCodeFromPromptSettings = BaseSettings & {
|
|
334
|
+
language?: "typescript";
|
|
335
|
+
framework: "react" | "html";
|
|
336
|
+
styling: "tailwind" | "inline_styles";
|
|
337
|
+
uiLibrary?: "shadcn";
|
|
338
|
+
};
|
|
339
|
+
|
|
235
340
|
/**
|
|
236
341
|
* Errors from the Website To Code Flow
|
|
237
342
|
*/
|
|
@@ -266,14 +371,14 @@ export declare type GetCodeFromWebsiteParams = {
|
|
|
266
371
|
webhookUrl?: string;
|
|
267
372
|
};
|
|
268
373
|
|
|
269
|
-
export declare type GetCodeFromWebsiteSettings = {
|
|
374
|
+
export declare type GetCodeFromWebsiteSettings = BaseSettings & {
|
|
270
375
|
language?: "typescript";
|
|
271
376
|
framework: "react" | "html";
|
|
272
377
|
styling: "tailwind" | "inline_styles";
|
|
273
378
|
uiLibrary?: "shadcn";
|
|
274
379
|
};
|
|
275
380
|
|
|
276
|
-
export declare type GetCodeHandler = ((message:
|
|
381
|
+
export declare type GetCodeHandler = ((message: SSEGetCodeFromFigmaMessage) => void) | {
|
|
277
382
|
onQueueing?: () => void;
|
|
278
383
|
onStart?: ({ sessionId }: {
|
|
279
384
|
sessionId: string;
|
|
@@ -467,7 +572,7 @@ export declare type L2CParamsStyling = 'tailwind' | 'inline-styles';
|
|
|
467
572
|
* @deprecated This type is deprecated and will be removed soon.
|
|
468
573
|
*/
|
|
469
574
|
export declare type L2CParamsUrlInput = {
|
|
470
|
-
type:
|
|
575
|
+
type: "url";
|
|
471
576
|
url: string;
|
|
472
577
|
};
|
|
473
578
|
|
|
@@ -479,6 +584,14 @@ export declare class NotFound extends Error {
|
|
|
479
584
|
});
|
|
480
585
|
}
|
|
481
586
|
|
|
587
|
+
export declare type ProgressMessage = {
|
|
588
|
+
id: string;
|
|
589
|
+
text: string;
|
|
590
|
+
attachments?: {
|
|
591
|
+
images?: string[];
|
|
592
|
+
};
|
|
593
|
+
};
|
|
594
|
+
|
|
482
595
|
export declare class RateLimitExceeded extends Error {
|
|
483
596
|
fileKey: string;
|
|
484
597
|
constructor({ fileKey, cause }: {
|
|
@@ -503,32 +616,49 @@ export declare class ResponseError extends Error {
|
|
|
503
616
|
/**
|
|
504
617
|
* Errors from the SDK
|
|
505
618
|
*/
|
|
506
|
-
export declare type SDKErrorReason = "Invalid body payload" | "
|
|
619
|
+
export declare type SDKErrorReason = "Invalid body payload" | "Connection closed before the 'done' message" | "Response body is null";
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* @deprecated This type is deprecated and will be removed soon.
|
|
623
|
+
*/
|
|
624
|
+
export declare type SSECodegenMessage = SSEGetCodeFromFigmaMessage;
|
|
625
|
+
|
|
626
|
+
export declare type SSECommonMessage = {
|
|
627
|
+
type: "queueing";
|
|
628
|
+
} | {
|
|
629
|
+
type: "progress_messages_updated";
|
|
630
|
+
payload: {
|
|
631
|
+
progressMessages: ProgressMessage[];
|
|
632
|
+
};
|
|
633
|
+
} | {
|
|
634
|
+
type: "aborted";
|
|
635
|
+
};
|
|
507
636
|
|
|
508
|
-
export declare type
|
|
637
|
+
export declare type SSEErrorPayload<Reason> = {
|
|
509
638
|
errorName: string;
|
|
510
639
|
task?: string;
|
|
511
|
-
reason:
|
|
640
|
+
reason: Reason;
|
|
512
641
|
sentryTraceId?: string;
|
|
513
642
|
};
|
|
514
643
|
|
|
515
|
-
export declare type
|
|
516
|
-
type: "queueing";
|
|
517
|
-
} | {
|
|
644
|
+
export declare type SSEGetCodeFromFigmaMessage = SSECommonMessage | {
|
|
518
645
|
type: "start";
|
|
519
646
|
sessionId: string;
|
|
520
|
-
} | {
|
|
521
|
-
type: "pre_codegen";
|
|
522
|
-
message: string;
|
|
523
647
|
} | {
|
|
524
648
|
type: "figma_metadata";
|
|
525
649
|
figmaFileName: string;
|
|
526
650
|
figmaSelectedFrameName: string;
|
|
651
|
+
} | {
|
|
652
|
+
type: "pre_codegen";
|
|
653
|
+
message: string;
|
|
527
654
|
} | {
|
|
528
655
|
type: "generating_code";
|
|
529
656
|
payload: GeneratingCodePayload;
|
|
530
657
|
} | {
|
|
531
658
|
type: "codegen_completed";
|
|
659
|
+
} | {
|
|
660
|
+
type: "post_codegen";
|
|
661
|
+
message: string;
|
|
532
662
|
} | {
|
|
533
663
|
type: "assets_uploaded";
|
|
534
664
|
} | {
|
|
@@ -539,11 +669,9 @@ export declare type SSECodgenMessage = {
|
|
|
539
669
|
url: string;
|
|
540
670
|
}>;
|
|
541
671
|
};
|
|
542
|
-
} | {
|
|
543
|
-
type: "aborted";
|
|
544
672
|
} | {
|
|
545
673
|
type: "error";
|
|
546
|
-
payload:
|
|
674
|
+
payload: SSEGetCodeFromFigmaMessageErrorPayload;
|
|
547
675
|
} | {
|
|
548
676
|
type: "done";
|
|
549
677
|
payload: {
|
|
@@ -552,26 +680,41 @@ export declare type SSECodgenMessage = {
|
|
|
552
680
|
};
|
|
553
681
|
};
|
|
554
682
|
|
|
555
|
-
export declare type
|
|
556
|
-
errorName: string;
|
|
557
|
-
task?: string;
|
|
558
|
-
reason: CodegenErrorReason;
|
|
559
|
-
};
|
|
683
|
+
export declare type SSEGetCodeFromFigmaMessageErrorPayload = SSEErrorPayload<GetCodeFromFigmaErrorReason>;
|
|
560
684
|
|
|
561
|
-
export declare type
|
|
562
|
-
type:
|
|
685
|
+
export declare type SSEGetCodeFromPromptMessage = SSECommonMessage | {
|
|
686
|
+
type: "start";
|
|
687
|
+
sessionId: string;
|
|
688
|
+
} | {
|
|
689
|
+
type: "generation_completed";
|
|
690
|
+
} | {
|
|
691
|
+
type: "error";
|
|
692
|
+
payload: SSEGetCodeFromPromptMessageErrorPayload;
|
|
563
693
|
} | {
|
|
564
|
-
type:
|
|
694
|
+
type: "done";
|
|
695
|
+
payload: {
|
|
696
|
+
sessionId: string;
|
|
697
|
+
tokenUsage: number;
|
|
698
|
+
};
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
export declare type SSEGetCodeFromPromptMessageErrorPayload = SSEErrorPayload<GetCodeFromPromptErrorReason>;
|
|
702
|
+
|
|
703
|
+
export declare type SSEGetCodeFromWebsiteMessage = SSECommonMessage | {
|
|
704
|
+
type: "start";
|
|
565
705
|
sessionId: string;
|
|
566
706
|
} | {
|
|
567
|
-
type:
|
|
707
|
+
type: "generating_code";
|
|
568
708
|
payload: GeneratingCodePayload;
|
|
569
709
|
} | {
|
|
570
|
-
type:
|
|
710
|
+
type: "generation_completed";
|
|
711
|
+
} | {
|
|
712
|
+
type: "post_codegen";
|
|
713
|
+
message: string;
|
|
571
714
|
} | {
|
|
572
|
-
type:
|
|
715
|
+
type: "assets_uploaded";
|
|
573
716
|
} | {
|
|
574
|
-
type:
|
|
717
|
+
type: "assets_list";
|
|
575
718
|
payload: {
|
|
576
719
|
assets: Array<{
|
|
577
720
|
name: string;
|
|
@@ -579,43 +722,38 @@ export declare type SSEGetCodeFromWebsiteMessage = {
|
|
|
579
722
|
}>;
|
|
580
723
|
};
|
|
581
724
|
} | {
|
|
582
|
-
type:
|
|
583
|
-
} | {
|
|
584
|
-
type: 'error';
|
|
725
|
+
type: "error";
|
|
585
726
|
payload: SSEGetCodeFromWebsiteMessageErrorPayload;
|
|
586
727
|
} | {
|
|
587
|
-
type:
|
|
728
|
+
type: "done";
|
|
588
729
|
payload: {
|
|
589
730
|
sessionId: string;
|
|
590
731
|
tokenUsage: number;
|
|
591
732
|
};
|
|
592
733
|
};
|
|
593
734
|
|
|
594
|
-
export declare type SSEGetCodeFromWebsiteMessageErrorPayload =
|
|
595
|
-
errorName: string;
|
|
596
|
-
task?: string;
|
|
597
|
-
reason: GetCodeFromWebsiteErrorReason;
|
|
598
|
-
sentryTraceId?: string;
|
|
599
|
-
};
|
|
735
|
+
export declare type SSEGetCodeFromWebsiteMessageErrorPayload = SSEErrorPayload<GetCodeFromWebsiteErrorReason>;
|
|
600
736
|
|
|
601
737
|
/**
|
|
602
738
|
* @deprecated This type is deprecated and will be removed soon.
|
|
603
739
|
*/
|
|
604
740
|
export declare type SSEL2CMessage = SSEGetCodeFromWebsiteMessage;
|
|
605
741
|
|
|
742
|
+
export declare type StreamCodeFromPromptMessage = StreamMessage<SSEGetCodeFromPromptMessage>;
|
|
743
|
+
|
|
606
744
|
export declare type StreamCodeFromWebsiteMessage = StreamMessage<SSEGetCodeFromWebsiteMessage>;
|
|
607
745
|
|
|
608
|
-
export declare type StreamCodgenMessage = StreamMessage<
|
|
746
|
+
export declare type StreamCodgenMessage = StreamMessage<SSEGetCodeFromFigmaMessage>;
|
|
609
747
|
|
|
610
748
|
declare type StreamErrorPayload = {
|
|
611
749
|
name: string;
|
|
612
|
-
message:
|
|
750
|
+
message: GetCodeFromFigmaErrorReason;
|
|
613
751
|
status?: number;
|
|
614
752
|
detail?: unknown;
|
|
615
|
-
errorPayload?:
|
|
753
|
+
errorPayload?: SSEGetCodeFromFigmaMessageErrorPayload;
|
|
616
754
|
};
|
|
617
755
|
|
|
618
|
-
export declare type StreamL2CMessage = StreamMessage<
|
|
756
|
+
export declare type StreamL2CMessage = StreamMessage<SSEGetCodeFromWebsiteMessage>;
|
|
619
757
|
|
|
620
758
|
export declare type StreamMessage<T> = Exclude<T, {
|
|
621
759
|
type: "error";
|