@kvasar/google-stitch 0.1.2 → 0.1.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/index.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
2
|
+
|
|
3
|
+
import { generateScreenFromTextTool } from "./src/tools/generate_screen_from_text_tool.js";
|
|
2
4
|
import { StitchMCPClient } from "./src/services/stitch-mcp-client.js";
|
|
3
5
|
import { createProjectTool } from "./src/tools/create_project.js";
|
|
4
6
|
import { getProjectTool } from "./src/tools/get_project.js";
|
|
5
7
|
import { listProjectsTool } from "./src/tools/list_projects.js";
|
|
6
8
|
import { listScreensTool } from "./src/tools/list_screens.js";
|
|
7
9
|
import { getScreenTool } from "./src/tools/get_screen.js";
|
|
8
|
-
import { generateScreenFromTextTool } from "./src/tools/generate_screen_from_text.js";
|
|
9
10
|
import { editScreensTool } from "./src/tools/edit_screens.js";
|
|
10
11
|
import { generateVariantsTool } from "./src/tools/generate_variants.js";
|
|
11
12
|
import { createDesignSystemTool } from "./src/tools/create_design_system.js";
|
|
@@ -13,12 +14,23 @@ import { updateDesignSystemTool } from "./src/tools/update_design_system.js";
|
|
|
13
14
|
import { listDesignSystemsTool } from "./src/tools/list_design_systems.js";
|
|
14
15
|
import { applyDesignSystemTool } from "./src/tools/apply_design_system.js";
|
|
15
16
|
|
|
17
|
+
interface StitchPluginConfig {
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
endpoint?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
16
23
|
export default definePluginEntry({
|
|
17
24
|
id: "openclaw-google-stitch",
|
|
18
25
|
name: "Google Stitch",
|
|
19
26
|
description: "Google Stitch integration for UI generation and design workflows",
|
|
20
27
|
register(api) {
|
|
21
|
-
|
|
28
|
+
const cfg = (
|
|
29
|
+
(api as { pluginConfig?: unknown; config?: unknown }).pluginConfig ??
|
|
30
|
+
(api as { pluginConfig?: unknown; config?: unknown }).config ??
|
|
31
|
+
{}
|
|
32
|
+
) as StitchPluginConfig;
|
|
33
|
+
|
|
22
34
|
if (!cfg?.apiKey || !cfg?.endpoint) {
|
|
23
35
|
throw new Error("Missing required configuration: apiKey and endpoint");
|
|
24
36
|
}
|
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { StitchMCPClient } from "../services/stitch-mcp-client.js";
|
|
2
|
+
|
|
3
|
+
type StitchGenerateResponse = {
|
|
4
|
+
html?: string;
|
|
5
|
+
code?: string;
|
|
6
|
+
jsx?: string;
|
|
7
|
+
previewHtml?: string;
|
|
8
|
+
result?: {
|
|
9
|
+
html?: string;
|
|
10
|
+
code?: string;
|
|
11
|
+
jsx?: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function generateScreenFromTextTool(client: StitchMCPClient) {
|
|
16
|
+
return {
|
|
17
|
+
name: "generate_screen_from_text",
|
|
18
|
+
description: "Generate a UI screen from a natural language prompt",
|
|
19
|
+
|
|
20
|
+
parameters: {
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
prompt: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Describe the UI screen to generate"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
required: ["prompt"]
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
async execute(_id: string, params: { prompt: string }) {
|
|
32
|
+
const result =
|
|
33
|
+
(await client.generateScreen(
|
|
34
|
+
params.prompt
|
|
35
|
+
)) as StitchGenerateResponse;
|
|
36
|
+
|
|
37
|
+
const html =
|
|
38
|
+
result.html ??
|
|
39
|
+
result.previewHtml ??
|
|
40
|
+
result.result?.html ??
|
|
41
|
+
(result.code
|
|
42
|
+
? `<pre style="white-space:pre-wrap;padding:16px">${escapeHtml(
|
|
43
|
+
result.code
|
|
44
|
+
)}</pre>`
|
|
45
|
+
: result.jsx
|
|
46
|
+
? `<pre style="white-space:pre-wrap;padding:16px">${escapeHtml(
|
|
47
|
+
result.jsx
|
|
48
|
+
)}</pre>`
|
|
49
|
+
: `<div style="padding:16px">
|
|
50
|
+
<h3>Screen generated</h3>
|
|
51
|
+
<pre>${escapeHtml(
|
|
52
|
+
JSON.stringify(result, null, 2)
|
|
53
|
+
)}</pre>
|
|
54
|
+
</div>`);
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
content: [
|
|
58
|
+
{
|
|
59
|
+
type: "html",
|
|
60
|
+
html
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function escapeHtml(str: string) {
|
|
69
|
+
return str
|
|
70
|
+
.replace(/&/g, "&")
|
|
71
|
+
.replace(/</g, "<")
|
|
72
|
+
.replace(/>/g, ">");
|
|
73
|
+
}
|