@animaapp/anima-sdk 0.6.11 → 0.6.12-beta.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.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +143 -3
- package/dist/index.js +413 -353
- 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,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,7 +96,7 @@ export declare class CodegenError extends Error {
|
|
|
63
96
|
detail?: unknown;
|
|
64
97
|
constructor({ name, reason, status, detail, }: {
|
|
65
98
|
name: string;
|
|
66
|
-
reason: CodegenErrorReason | CodegenRouteErrorReason | SDKErrorReason | GetCodeFromWebsiteErrorReason;
|
|
99
|
+
reason: CodegenErrorReason | CodegenRouteErrorReason | SDKErrorReason | GetCodeFromWebsiteErrorReason | GetCodeFromPromptErrorReason;
|
|
67
100
|
status?: number;
|
|
68
101
|
detail?: unknown;
|
|
69
102
|
});
|
|
@@ -105,10 +138,35 @@ export declare type CodegenSettings = {
|
|
|
105
138
|
allowAutoSelectFirstNode?: boolean;
|
|
106
139
|
enableDisplayScreenModelId?: boolean;
|
|
107
140
|
enableGeneratePackageLock?: boolean;
|
|
141
|
+
enableAnimationsPreset?: boolean;
|
|
108
142
|
url?: string;
|
|
109
143
|
codegenSettings?: Record<string, unknown>;
|
|
110
144
|
};
|
|
111
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Creates a Server-Sent Events (SSE) `Response` that forwards all messages from the code generation from prompt stream.
|
|
148
|
+
*
|
|
149
|
+
* But, if the first message indicates an error (e.g., connection failed), the function returns a 500 response with the error message.
|
|
150
|
+
*
|
|
151
|
+
* @param {Anima} anima - The Anima instance to use for creating the data stream.
|
|
152
|
+
* @param {GetCodeFromPromptParams} params - The parameters for the code generation request.
|
|
153
|
+
* @returns {Promise<Response>} - A promise that resolves to an HTTP response.
|
|
154
|
+
*/
|
|
155
|
+
export declare const createCodeFromPromptResponseEventStream: (anima: Anima, params: GetCodeFromPromptParams) => Promise<Response>;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Prompt to Code (p2c) stream flow.
|
|
159
|
+
*
|
|
160
|
+
* Start the prompt to code generation and creates a ReadableStream to output its result.
|
|
161
|
+
*
|
|
162
|
+
* The stream is closed when the code generation ends.
|
|
163
|
+
*
|
|
164
|
+
* @param {Anima} anima - An Anima service instance to generate the code from.
|
|
165
|
+
* @param {GetCodeFromPromptParams} params - Parameters required for the code generation process.
|
|
166
|
+
* @returns {ReadableStream<StreamCodeFromPromptMessage>} - A ReadableStream that emits messages related to the code generation process.
|
|
167
|
+
*/
|
|
168
|
+
export declare const createCodeFromPromptStream: (anima: Anima, params: GetCodeFromPromptParams) => ReadableStream<StreamCodeFromPromptMessage>;
|
|
169
|
+
|
|
112
170
|
/**
|
|
113
171
|
* Creates a Server-Sent Events (SSE) `Response` that forwards all messages from the code generation from website stream.
|
|
114
172
|
*
|
|
@@ -224,6 +282,46 @@ export declare type GeneratingCodePayload = {
|
|
|
224
282
|
files: AnimaFiles;
|
|
225
283
|
};
|
|
226
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Errors from the Prompt To Code Flow
|
|
287
|
+
*/
|
|
288
|
+
export declare type GetCodeFromPromptErrorReason = "Invalid prompt" | "Generation failed" | "Unknown";
|
|
289
|
+
|
|
290
|
+
export declare type GetCodeFromPromptHandler = ((message: SSEGetCodeFromPromptMessage) => void) | {
|
|
291
|
+
onQueueing?: () => void;
|
|
292
|
+
onStart?: ({ sessionId }: {
|
|
293
|
+
sessionId: string;
|
|
294
|
+
}) => void;
|
|
295
|
+
onAssetsUploaded?: () => void;
|
|
296
|
+
onAssetsList?: ({ assets, }: {
|
|
297
|
+
assets: Array<{
|
|
298
|
+
name: string;
|
|
299
|
+
url: string;
|
|
300
|
+
}>;
|
|
301
|
+
}) => void;
|
|
302
|
+
onGeneratingCode?: ({ status, progress, files, }: {
|
|
303
|
+
status: "success" | "running" | "failure";
|
|
304
|
+
progress: number;
|
|
305
|
+
files: AnimaFiles;
|
|
306
|
+
}) => void;
|
|
307
|
+
onCodegenCompleted?: () => void;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export declare type GetCodeFromPromptParams = {
|
|
311
|
+
prompt: string;
|
|
312
|
+
assetsStorage?: AssetsStorage;
|
|
313
|
+
settings: GetCodeFromPromptSettings;
|
|
314
|
+
tracking?: TrackingInfos;
|
|
315
|
+
webhookUrl?: string;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
export declare type GetCodeFromPromptSettings = {
|
|
319
|
+
language?: "typescript";
|
|
320
|
+
framework: "react" | "html";
|
|
321
|
+
styling: "tailwind" | "inline_styles";
|
|
322
|
+
uiLibrary?: "shadcn";
|
|
323
|
+
};
|
|
324
|
+
|
|
227
325
|
/**
|
|
228
326
|
* Errors from the Website To Code Flow
|
|
229
327
|
*/
|
|
@@ -549,6 +647,46 @@ export declare type SSECodgenMessageErrorPayload = {
|
|
|
549
647
|
reason: CodegenErrorReason;
|
|
550
648
|
};
|
|
551
649
|
|
|
650
|
+
export declare type SSEGetCodeFromPromptMessage = {
|
|
651
|
+
type: 'queueing';
|
|
652
|
+
} | {
|
|
653
|
+
type: 'start';
|
|
654
|
+
sessionId: string;
|
|
655
|
+
} | {
|
|
656
|
+
type: 'generating_code';
|
|
657
|
+
payload: GeneratingCodePayload;
|
|
658
|
+
} | {
|
|
659
|
+
type: 'generation_completed';
|
|
660
|
+
} | {
|
|
661
|
+
type: 'assets_uploaded';
|
|
662
|
+
} | {
|
|
663
|
+
type: 'assets_list';
|
|
664
|
+
payload: {
|
|
665
|
+
assets: Array<{
|
|
666
|
+
name: string;
|
|
667
|
+
url: string;
|
|
668
|
+
}>;
|
|
669
|
+
};
|
|
670
|
+
} | {
|
|
671
|
+
type: 'aborted';
|
|
672
|
+
} | {
|
|
673
|
+
type: 'error';
|
|
674
|
+
payload: SSEGetCodeFromPromptMessageErrorPayload;
|
|
675
|
+
} | {
|
|
676
|
+
type: 'done';
|
|
677
|
+
payload: {
|
|
678
|
+
sessionId: string;
|
|
679
|
+
tokenUsage: number;
|
|
680
|
+
};
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
export declare type SSEGetCodeFromPromptMessageErrorPayload = {
|
|
684
|
+
errorName: string;
|
|
685
|
+
task?: string;
|
|
686
|
+
reason: GetCodeFromPromptErrorReason;
|
|
687
|
+
sentryTraceId?: string;
|
|
688
|
+
};
|
|
689
|
+
|
|
552
690
|
export declare type SSEGetCodeFromWebsiteMessage = {
|
|
553
691
|
type: 'queueing';
|
|
554
692
|
} | {
|
|
@@ -594,6 +732,8 @@ export declare type SSEGetCodeFromWebsiteMessageErrorPayload = {
|
|
|
594
732
|
*/
|
|
595
733
|
export declare type SSEL2CMessage = SSEGetCodeFromWebsiteMessage;
|
|
596
734
|
|
|
735
|
+
export declare type StreamCodeFromPromptMessage = StreamMessage<SSEGetCodeFromPromptMessage>;
|
|
736
|
+
|
|
597
737
|
export declare type StreamCodeFromWebsiteMessage = StreamMessage<SSEGetCodeFromWebsiteMessage>;
|
|
598
738
|
|
|
599
739
|
export declare type StreamCodgenMessage = StreamMessage<SSECodgenMessage>;
|