@animaapp/anima-sdk 0.1.0 → 0.2.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/.turbo/turbo-build.log +6 -6
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +28 -0
- package/dist/index.js +1058 -1048
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
- package/src/anima.ts +22 -10
- package/src/dataStream.ts +2 -1
- package/src/settings.ts +4 -0
- package/src/types.ts +15 -0
- package/tsconfig.json +5 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@animaapp/anima-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Anima's JavaScript utilities library",
|
|
6
6
|
"author": "Anima App, Inc.",
|
|
@@ -16,8 +16,7 @@
|
|
|
16
16
|
"url": "git+https://github.com/AnimaApp/anima-sdk.git"
|
|
17
17
|
},
|
|
18
18
|
"publishConfig": {
|
|
19
|
-
"access": "public"
|
|
20
|
-
"registry": "https://registry.npmjs.org/"
|
|
19
|
+
"access": "public"
|
|
21
20
|
},
|
|
22
21
|
"scripts": {
|
|
23
22
|
"build": "vite build",
|
|
@@ -35,4 +34,4 @@
|
|
|
35
34
|
"vite-tsconfig-paths": "^5.1.4",
|
|
36
35
|
"vitest": "^3.0.5"
|
|
37
36
|
}
|
|
38
|
-
}
|
|
37
|
+
}
|
package/src/anima.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { convertCodegenFilesToAnimaFiles } from "./codegenToAnimaFiles";
|
|
1
2
|
import { CodegenError } from "./errors";
|
|
2
3
|
import { validateSettings } from "./settings";
|
|
3
4
|
import {
|
|
4
|
-
AnimaFiles,
|
|
5
5
|
AnimaSDKResult,
|
|
6
6
|
GetCodeHandler,
|
|
7
7
|
GetCodeParams,
|
|
8
8
|
SSECodgenMessage,
|
|
9
9
|
} from "./types";
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
export type Auth =
|
|
12
12
|
| { token: string; teamId: string } // for Anima user, it's mandatory to have an associated team
|
|
13
13
|
| { token: string; userId?: string }; // for users from a 3rd-party client (e.g., Bolt) they may have optionally a user id
|
|
@@ -77,11 +77,14 @@ export class Anima {
|
|
|
77
77
|
fileKey: params.fileKey,
|
|
78
78
|
figmaToken: params.figmaToken,
|
|
79
79
|
nodesId: params.nodesId,
|
|
80
|
+
assetsStorage: params.assetsStorage,
|
|
80
81
|
language: settings.language,
|
|
82
|
+
model: settings.model,
|
|
81
83
|
framework: settings.framework,
|
|
82
84
|
styling: settings.styling,
|
|
83
85
|
uiLibrary: settings.uiLibrary,
|
|
84
86
|
enableTranslation: settings.enableTranslation,
|
|
87
|
+
enableUILibraryTheming: settings.enableUILibraryTheming,
|
|
85
88
|
}),
|
|
86
89
|
});
|
|
87
90
|
|
|
@@ -162,6 +165,15 @@ export class Anima {
|
|
|
162
165
|
break;
|
|
163
166
|
}
|
|
164
167
|
|
|
168
|
+
case "assets_list": {
|
|
169
|
+
result.assets = data.payload.assets;
|
|
170
|
+
|
|
171
|
+
typeof handler === "function"
|
|
172
|
+
? handler(data)
|
|
173
|
+
: handler.onAssetsList?.(data.payload);
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
|
|
165
177
|
case "figma_metadata": {
|
|
166
178
|
result.figmaFileName = data.figmaFileName;
|
|
167
179
|
result.figmaSelectedFrameName = data.figmaSelectedFrameName;
|
|
@@ -169,9 +181,9 @@ export class Anima {
|
|
|
169
181
|
typeof handler === "function"
|
|
170
182
|
? handler(data)
|
|
171
183
|
: handler.onFigmaMetadata?.({
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
184
|
+
figmaFileName: data.figmaFileName,
|
|
185
|
+
figmaSelectedFrameName: data.figmaSelectedFrameName,
|
|
186
|
+
});
|
|
175
187
|
break;
|
|
176
188
|
}
|
|
177
189
|
|
|
@@ -182,7 +194,7 @@ export class Anima {
|
|
|
182
194
|
>;
|
|
183
195
|
|
|
184
196
|
const files = convertCodegenFilesToAnimaFiles(codegenFiles);
|
|
185
|
-
|
|
197
|
+
|
|
186
198
|
if (data.payload.status === "success") {
|
|
187
199
|
result.files = files;
|
|
188
200
|
}
|
|
@@ -190,10 +202,10 @@ export class Anima {
|
|
|
190
202
|
typeof handler === "function"
|
|
191
203
|
? handler(data)
|
|
192
204
|
: handler.onGeneratingCode?.({
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
205
|
+
status: data.payload.status,
|
|
206
|
+
progress: data.payload.progress,
|
|
207
|
+
files,
|
|
208
|
+
});
|
|
197
209
|
break;
|
|
198
210
|
}
|
|
199
211
|
|
package/src/dataStream.ts
CHANGED
|
@@ -86,13 +86,14 @@ export const createCodegenResponseEventStream = async (
|
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
const encoder = new TextEncoder();
|
|
89
90
|
const seeStream = consumerStream.pipeThrough(
|
|
90
91
|
new TransformStream({
|
|
91
92
|
transform(chunk, controller) {
|
|
92
93
|
const sseString = `event: ${chunk.type}\ndata: ${JSON.stringify(
|
|
93
94
|
chunk
|
|
94
95
|
)}\n\n`;
|
|
95
|
-
controller.enqueue(sseString);
|
|
96
|
+
controller.enqueue(encoder.encode(sseString));
|
|
96
97
|
},
|
|
97
98
|
})
|
|
98
99
|
);
|
package/src/settings.ts
CHANGED
|
@@ -8,6 +8,7 @@ const CodegenSettingsSchema = z
|
|
|
8
8
|
z.union([
|
|
9
9
|
z.object({
|
|
10
10
|
framework: z.literal("react"),
|
|
11
|
+
model: z.string().optional(),
|
|
11
12
|
styling: z.enum([
|
|
12
13
|
"plain_css",
|
|
13
14
|
"css_modules",
|
|
@@ -18,6 +19,7 @@ const CodegenSettingsSchema = z
|
|
|
18
19
|
"inline_styles",
|
|
19
20
|
]),
|
|
20
21
|
uiLibrary: z.enum(["mui", "antd", "radix", "shadcn"]).optional(),
|
|
22
|
+
enableUILibraryTheming: z.boolean().optional(),
|
|
21
23
|
}),
|
|
22
24
|
z.object({
|
|
23
25
|
framework: z.literal("html"),
|
|
@@ -30,6 +32,7 @@ const CodegenSettingsSchema = z
|
|
|
30
32
|
// We don't use the z.infer method here because the types returned by zod aren't ergonic
|
|
31
33
|
export type CodegenSettings = {
|
|
32
34
|
language?: "typescript" | "javascript";
|
|
35
|
+
model?: string,
|
|
33
36
|
framework: "react" | "html";
|
|
34
37
|
styling:
|
|
35
38
|
| "plain_css"
|
|
@@ -41,6 +44,7 @@ export type CodegenSettings = {
|
|
|
41
44
|
| "inline_styles"
|
|
42
45
|
uiLibrary?: "mui" | "antd" | "radix" | "shadcn";
|
|
43
46
|
enableTranslation?: boolean;
|
|
47
|
+
enableUILibraryTheming?: boolean;
|
|
44
48
|
};
|
|
45
49
|
|
|
46
50
|
export const validateSettings = (obj: unknown): CodegenSettings => {
|
package/src/types.ts
CHANGED
|
@@ -17,16 +17,22 @@ export type BaseResult = {
|
|
|
17
17
|
|
|
18
18
|
export type AnimaSDKResult = BaseResult & {
|
|
19
19
|
files: AnimaFiles;
|
|
20
|
+
assets?: Array<{ name: string; url: string }>;
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
export type CodegenResult = BaseResult & {
|
|
23
24
|
files: Record<string, { code: string; type: "code" }>;
|
|
24
25
|
};
|
|
25
26
|
|
|
27
|
+
export type AssetsStorage =
|
|
28
|
+
| { strategy: "host" }
|
|
29
|
+
| { strategy: "external"; url: string };
|
|
30
|
+
|
|
26
31
|
export type GetCodeParams = {
|
|
27
32
|
fileKey: string;
|
|
28
33
|
figmaToken: string;
|
|
29
34
|
nodesId: string[];
|
|
35
|
+
assetsStorage?: AssetsStorage;
|
|
30
36
|
settings: CodegenSettings;
|
|
31
37
|
};
|
|
32
38
|
|
|
@@ -36,6 +42,11 @@ export type GetCodeHandler =
|
|
|
36
42
|
onStart?: ({ sessionId }: { sessionId: string }) => void;
|
|
37
43
|
onPreCodegen?: ({ message }: { message: string }) => void;
|
|
38
44
|
onAssetsUploaded?: () => void;
|
|
45
|
+
onAssetsList?: ({
|
|
46
|
+
assets,
|
|
47
|
+
}: {
|
|
48
|
+
assets: Array<{ name: string; url: string }>;
|
|
49
|
+
}) => void;
|
|
39
50
|
onFigmaMetadata?: ({
|
|
40
51
|
figmaFileName,
|
|
41
52
|
figmaSelectedFrameName,
|
|
@@ -67,6 +78,10 @@ export type SSECodgenMessage =
|
|
|
67
78
|
| { type: "generating_code"; payload: any }
|
|
68
79
|
| { type: "codegen_completed" }
|
|
69
80
|
| { type: "assets_uploaded" }
|
|
81
|
+
| {
|
|
82
|
+
type: "assets_list";
|
|
83
|
+
payload: { assets: Array<{ name: string; url: string }> };
|
|
84
|
+
}
|
|
70
85
|
| { type: "aborted" }
|
|
71
86
|
| { type: "error"; payload: SSECodgenMessageErrorPayload }
|
|
72
87
|
| { type: "done" };
|