@kvasar/google-stitch 0.1.3 → 0.1.5

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";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "openclaw-google-stitch",
3
3
  "name": "Google Stitch MCP",
4
- "version": "0.1.3",
4
+ "version": "0.1.5",
5
5
  "description": "Integrates Google Stitch MCP services into OpenClaw",
6
6
  "skills": ["skills"],
7
7
  "configSchema": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kvasar/google-stitch",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "OpenClaw plugin for Google Stitch UI generation, screen design, variants, and design systems",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -1,15 +1,48 @@
1
1
  export class StitchMCPClient {
2
- constructor(private config: { apiKey: string; endpoint: string }) {}
2
+ constructor(
3
+ private config: { apiKey: string; endpoint: string }
4
+ ) {
5
+ if (!config.apiKey) {
6
+ throw new Error("Missing Stitch apiKey");
7
+ }
8
+
9
+ if (!config.endpoint) {
10
+ throw new Error("Missing Stitch endpoint");
11
+ }
12
+ }
13
+
3
14
  private async request(path: string, body?: unknown) {
4
- const response = await fetch(`${this.config.endpoint}/${path}`, {
5
- method: "POST",
6
- headers: {
7
- "Content-Type": "application/json",
8
- Authorization: `Bearer ${this.config.apiKey}`,
9
- },
10
- body: body ? JSON.stringify(body) : undefined,
11
- });
12
- if (!response.ok) throw new Error(`Stitch API error: ${response.status}`);
15
+ const cleanPath = path.startsWith("/")
16
+ ? path.slice(1)
17
+ : path;
18
+
19
+ const response = await fetch(
20
+ `${this.config.endpoint}/${cleanPath}`,
21
+ {
22
+ method: "POST",
23
+ headers: {
24
+ "Content-Type": "application/json",
25
+ "X-Goog-Api-Key": this.config.apiKey,
26
+ },
27
+ body: body
28
+ ? JSON.stringify(body)
29
+ : undefined,
30
+ }
31
+ );
32
+
33
+ if (!response.ok) {
34
+ const errorText = await response.text();
35
+ throw new Error(
36
+ `Stitch API error: ${response.status} - ${errorText}`
37
+ );
38
+ }
39
+
13
40
  return response.json();
14
41
  }
15
- }
42
+
43
+ async generateScreen(prompt: string) {
44
+ return this.request("generate-screen", {
45
+ prompt,
46
+ });
47
+ }
48
+ }
@@ -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, "&amp;")
71
+ .replace(/</g, "&lt;")
72
+ .replace(/>/g, "&gt;");
73
+ }