@kohryan/moodui 0.0.2 → 0.0.4
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/chunk-5D6KNM5J.mjs +570 -0
- package/dist/cli.d.mts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +715 -0
- package/dist/cli.mjs +137 -0
- package/dist/index.d.mts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +489 -114
- package/dist/index.mjs +307 -493
- package/package.json +7 -2
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateReactFromPrompt
|
|
3
|
+
} from "./chunk-5D6KNM5J.mjs";
|
|
4
|
+
|
|
5
|
+
// src/cli.ts
|
|
6
|
+
import fs from "fs/promises";
|
|
7
|
+
import path from "path";
|
|
8
|
+
async function main() {
|
|
9
|
+
const argv = process.argv.slice(2);
|
|
10
|
+
const command = argv[0] ?? "help";
|
|
11
|
+
if (command === "help" || command === "--help" || command === "-h") {
|
|
12
|
+
printHelp();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (command !== "generate") {
|
|
16
|
+
console.error(`Unknown command: ${command}`);
|
|
17
|
+
printHelp();
|
|
18
|
+
process.exitCode = 1;
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const { args, positionals } = parseArgs(argv.slice(1));
|
|
22
|
+
const provider = args.provider || "gemini";
|
|
23
|
+
const model = args.model || (provider === "gemini" ? "gemini-3-flash-preview" : "");
|
|
24
|
+
const outFile = args.out || "src/generated/MoodScreen.tsx";
|
|
25
|
+
const componentName = args.component || "MoodScreen";
|
|
26
|
+
const prompt = args.prompt || positionals.join(" ");
|
|
27
|
+
if (!model) {
|
|
28
|
+
console.error("Missing --model");
|
|
29
|
+
process.exitCode = 1;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!prompt) {
|
|
33
|
+
console.error('Missing prompt. Use --prompt "..." or pass it as arguments.');
|
|
34
|
+
process.exitCode = 1;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const temperature = args.temperature != null ? Number(args.temperature) : void 0;
|
|
38
|
+
const maxAttempts = args.maxAttempts != null ? Number(args.maxAttempts) : void 0;
|
|
39
|
+
const baseUrl = typeof args.baseUrl === "string" ? args.baseUrl : void 0;
|
|
40
|
+
if (provider === "gemini" && !process.env.GEMINI_API_KEY) {
|
|
41
|
+
console.error("Missing GEMINI_API_KEY env var");
|
|
42
|
+
process.exitCode = 1;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (provider === "openai-compatible" && !process.env.OPENAI_COMPATIBLE_API_KEY) {
|
|
46
|
+
console.error("Missing OPENAI_COMPATIBLE_API_KEY env var");
|
|
47
|
+
process.exitCode = 1;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const result = provider === "ollama" ? await generateReactFromPrompt({
|
|
51
|
+
provider: "ollama",
|
|
52
|
+
model,
|
|
53
|
+
baseUrl,
|
|
54
|
+
prompt,
|
|
55
|
+
componentName,
|
|
56
|
+
temperature,
|
|
57
|
+
maxAttempts
|
|
58
|
+
}) : provider === "openai-compatible" ? await generateReactFromPrompt({
|
|
59
|
+
provider: "openai-compatible",
|
|
60
|
+
model,
|
|
61
|
+
baseUrl: baseUrl || process.env.OPENAI_COMPATIBLE_BASE_URL || "",
|
|
62
|
+
apiKey: process.env.OPENAI_COMPATIBLE_API_KEY || "",
|
|
63
|
+
prompt,
|
|
64
|
+
componentName,
|
|
65
|
+
temperature,
|
|
66
|
+
maxAttempts
|
|
67
|
+
}) : await generateReactFromPrompt({
|
|
68
|
+
provider: "gemini",
|
|
69
|
+
model,
|
|
70
|
+
baseUrl,
|
|
71
|
+
apiKey: process.env.GEMINI_API_KEY || "",
|
|
72
|
+
prompt,
|
|
73
|
+
componentName,
|
|
74
|
+
temperature,
|
|
75
|
+
maxAttempts
|
|
76
|
+
});
|
|
77
|
+
const resolvedOut = path.resolve(process.cwd(), outFile);
|
|
78
|
+
await fs.mkdir(path.dirname(resolvedOut), { recursive: true });
|
|
79
|
+
await fs.writeFile(resolvedOut, result.code, "utf8");
|
|
80
|
+
console.log(`OK: wrote ${resolvedOut}`);
|
|
81
|
+
}
|
|
82
|
+
function printHelp() {
|
|
83
|
+
console.log(
|
|
84
|
+
[
|
|
85
|
+
"moodui generate [options] <prompt...>",
|
|
86
|
+
"",
|
|
87
|
+
"Options:",
|
|
88
|
+
" --provider gemini|ollama|openai-compatible default: gemini",
|
|
89
|
+
" --model <name> required (default for gemini: gemini-3-flash-preview)",
|
|
90
|
+
" --out <path> default: src/generated/MoodScreen.tsx",
|
|
91
|
+
" --component <name> default: MoodScreen",
|
|
92
|
+
" --prompt <text> optional (or pass as positional args)",
|
|
93
|
+
" --temperature <number>",
|
|
94
|
+
" --maxAttempts <number>",
|
|
95
|
+
" --baseUrl <url>",
|
|
96
|
+
"",
|
|
97
|
+
"Env:",
|
|
98
|
+
" GEMINI_API_KEY",
|
|
99
|
+
" OPENAI_COMPATIBLE_BASE_URL",
|
|
100
|
+
" OPENAI_COMPATIBLE_API_KEY",
|
|
101
|
+
"",
|
|
102
|
+
"Example:",
|
|
103
|
+
' GEMINI_API_KEY=... npx @kohryan/moodui generate --model gemini-3-flash-preview "Buat UI login sederhana"'
|
|
104
|
+
].join("\n")
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
function parseArgs(argv) {
|
|
108
|
+
const args = {};
|
|
109
|
+
const positionals = [];
|
|
110
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
111
|
+
const token = argv[i];
|
|
112
|
+
if (!token.startsWith("--")) {
|
|
113
|
+
positionals.push(token);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const eq = token.indexOf("=");
|
|
117
|
+
const key = (eq >= 0 ? token.slice(2, eq) : token.slice(2)).trim();
|
|
118
|
+
const inlineValue = eq >= 0 ? token.slice(eq + 1) : void 0;
|
|
119
|
+
if (inlineValue != null) {
|
|
120
|
+
args[key] = inlineValue;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const next = argv[i + 1];
|
|
124
|
+
if (next == null || next.startsWith("--")) {
|
|
125
|
+
args[key] = true;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
args[key] = next;
|
|
129
|
+
i += 1;
|
|
130
|
+
}
|
|
131
|
+
return { args, positionals };
|
|
132
|
+
}
|
|
133
|
+
main().catch((e) => {
|
|
134
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
135
|
+
console.error(msg);
|
|
136
|
+
process.exitCode = 1;
|
|
137
|
+
});
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
1
3
|
type MoodUISpecVersion = 1;
|
|
2
4
|
type MoodUISpec = {
|
|
3
5
|
version: MoodUISpecVersion;
|
|
@@ -113,6 +115,22 @@ type _RenderReactExports = {
|
|
|
113
115
|
renderReactJSX: typeof renderReactJSX;
|
|
114
116
|
};
|
|
115
117
|
|
|
118
|
+
type MoodUIRuntimeProps = {
|
|
119
|
+
spec: MoodUISpec;
|
|
120
|
+
onAction?: (actionId: string) => void;
|
|
121
|
+
};
|
|
122
|
+
declare function MoodUIRuntime(props: MoodUIRuntimeProps): react_jsx_runtime.JSX.Element;
|
|
123
|
+
|
|
124
|
+
type MoodUIPromptPlaygroundProps = {
|
|
125
|
+
provider?: "gemini" | "ollama" | "openai-compatible";
|
|
126
|
+
model?: string;
|
|
127
|
+
apiKey?: string;
|
|
128
|
+
baseUrl?: string;
|
|
129
|
+
defaultPrompt?: string;
|
|
130
|
+
componentName?: string;
|
|
131
|
+
};
|
|
132
|
+
declare function MoodUIPromptPlayground(props: MoodUIPromptPlaygroundProps): react_jsx_runtime.JSX.Element;
|
|
133
|
+
|
|
116
134
|
type LLMMessage = {
|
|
117
135
|
role: "system" | "user" | "assistant";
|
|
118
136
|
content: string;
|
|
@@ -187,4 +205,4 @@ type GenerateReactFromPromptResult = {
|
|
|
187
205
|
};
|
|
188
206
|
declare function generateReactFromPrompt(options: GenerateReactFromPromptOptions): Promise<GenerateReactFromPromptResult>;
|
|
189
207
|
|
|
190
|
-
export { type GeminiClientOptions, type GenerateReactFromPromptOptions, type GenerateReactFromPromptResult, type GenerateSpecOptions, type GenerateSpecResult, type LLMChatClient, type LLMChatRequest, type LLMMessage, type MoodUIBoxNode, type MoodUIButtonNode, type MoodUIColor, type MoodUICommonProps, type MoodUIImageNode, type MoodUIInputNode, type MoodUINode, type MoodUIRadius, type MoodUISpace, type MoodUISpacerNode, type MoodUISpec, type MoodUISpecVersion, type MoodUITextNode, type MoodUITheme, type OllamaClientOptions, type OpenAICompatibleClientOptions, type RenderReactOptions, type ValidationResult, type _InternalNodeTypes, type _RenderReactExports, assertMoodUISpec, createGeminiClient, createOllamaClient, createOpenAICompatibleClient, generateMoodUISpec, generateReactFromPrompt, renderReact, renderReactJSX, validateMoodUISpec };
|
|
208
|
+
export { type GeminiClientOptions, type GenerateReactFromPromptOptions, type GenerateReactFromPromptResult, type GenerateSpecOptions, type GenerateSpecResult, type LLMChatClient, type LLMChatRequest, type LLMMessage, type MoodUIBoxNode, type MoodUIButtonNode, type MoodUIColor, type MoodUICommonProps, type MoodUIImageNode, type MoodUIInputNode, type MoodUINode, MoodUIPromptPlayground, type MoodUIPromptPlaygroundProps, type MoodUIRadius, MoodUIRuntime, type MoodUIRuntimeProps, type MoodUISpace, type MoodUISpacerNode, type MoodUISpec, type MoodUISpecVersion, type MoodUITextNode, type MoodUITheme, type OllamaClientOptions, type OpenAICompatibleClientOptions, type RenderReactOptions, type ValidationResult, type _InternalNodeTypes, type _RenderReactExports, assertMoodUISpec, createGeminiClient, createOllamaClient, createOpenAICompatibleClient, generateMoodUISpec, generateReactFromPrompt, renderReact, renderReactJSX, validateMoodUISpec };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
1
3
|
type MoodUISpecVersion = 1;
|
|
2
4
|
type MoodUISpec = {
|
|
3
5
|
version: MoodUISpecVersion;
|
|
@@ -113,6 +115,22 @@ type _RenderReactExports = {
|
|
|
113
115
|
renderReactJSX: typeof renderReactJSX;
|
|
114
116
|
};
|
|
115
117
|
|
|
118
|
+
type MoodUIRuntimeProps = {
|
|
119
|
+
spec: MoodUISpec;
|
|
120
|
+
onAction?: (actionId: string) => void;
|
|
121
|
+
};
|
|
122
|
+
declare function MoodUIRuntime(props: MoodUIRuntimeProps): react_jsx_runtime.JSX.Element;
|
|
123
|
+
|
|
124
|
+
type MoodUIPromptPlaygroundProps = {
|
|
125
|
+
provider?: "gemini" | "ollama" | "openai-compatible";
|
|
126
|
+
model?: string;
|
|
127
|
+
apiKey?: string;
|
|
128
|
+
baseUrl?: string;
|
|
129
|
+
defaultPrompt?: string;
|
|
130
|
+
componentName?: string;
|
|
131
|
+
};
|
|
132
|
+
declare function MoodUIPromptPlayground(props: MoodUIPromptPlaygroundProps): react_jsx_runtime.JSX.Element;
|
|
133
|
+
|
|
116
134
|
type LLMMessage = {
|
|
117
135
|
role: "system" | "user" | "assistant";
|
|
118
136
|
content: string;
|
|
@@ -187,4 +205,4 @@ type GenerateReactFromPromptResult = {
|
|
|
187
205
|
};
|
|
188
206
|
declare function generateReactFromPrompt(options: GenerateReactFromPromptOptions): Promise<GenerateReactFromPromptResult>;
|
|
189
207
|
|
|
190
|
-
export { type GeminiClientOptions, type GenerateReactFromPromptOptions, type GenerateReactFromPromptResult, type GenerateSpecOptions, type GenerateSpecResult, type LLMChatClient, type LLMChatRequest, type LLMMessage, type MoodUIBoxNode, type MoodUIButtonNode, type MoodUIColor, type MoodUICommonProps, type MoodUIImageNode, type MoodUIInputNode, type MoodUINode, type MoodUIRadius, type MoodUISpace, type MoodUISpacerNode, type MoodUISpec, type MoodUISpecVersion, type MoodUITextNode, type MoodUITheme, type OllamaClientOptions, type OpenAICompatibleClientOptions, type RenderReactOptions, type ValidationResult, type _InternalNodeTypes, type _RenderReactExports, assertMoodUISpec, createGeminiClient, createOllamaClient, createOpenAICompatibleClient, generateMoodUISpec, generateReactFromPrompt, renderReact, renderReactJSX, validateMoodUISpec };
|
|
208
|
+
export { type GeminiClientOptions, type GenerateReactFromPromptOptions, type GenerateReactFromPromptResult, type GenerateSpecOptions, type GenerateSpecResult, type LLMChatClient, type LLMChatRequest, type LLMMessage, type MoodUIBoxNode, type MoodUIButtonNode, type MoodUIColor, type MoodUICommonProps, type MoodUIImageNode, type MoodUIInputNode, type MoodUINode, MoodUIPromptPlayground, type MoodUIPromptPlaygroundProps, type MoodUIRadius, MoodUIRuntime, type MoodUIRuntimeProps, type MoodUISpace, type MoodUISpacerNode, type MoodUISpec, type MoodUISpecVersion, type MoodUITextNode, type MoodUITheme, type OllamaClientOptions, type OpenAICompatibleClientOptions, type RenderReactOptions, type ValidationResult, type _InternalNodeTypes, type _RenderReactExports, assertMoodUISpec, createGeminiClient, createOllamaClient, createOpenAICompatibleClient, generateMoodUISpec, generateReactFromPrompt, renderReact, renderReactJSX, validateMoodUISpec };
|