@kvasar/google-stitch 0.1.19 → 0.1.20

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "openclaw-google-stitch",
3
3
  "name": "Google Stitch MCP",
4
- "version": "0.1.19",
4
+ "version": "0.1.20",
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.19",
3
+ "version": "0.1.20",
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",
@@ -0,0 +1,165 @@
1
+ import { StitchMCPClient } from "../services/stitch-mcp-client.js";
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+
6
+ type StitchFile = {
7
+ name?: string;
8
+ downloadUrl?: string;
9
+ mimeType?: string;
10
+ fileContentBase64?: string;
11
+ };
12
+
13
+ type Screen = {
14
+ name?: string;
15
+ id?: string;
16
+ title?: string;
17
+ prompt?: string;
18
+ screenshot?: StitchFile;
19
+ htmlCode?: StitchFile;
20
+ figmaExport?: StitchFile;
21
+ deviceType?: string;
22
+ width?: string;
23
+ height?: string;
24
+ groupId?: string;
25
+ groupName?: string;
26
+ generatedBy?: string;
27
+ isCreatedByClient?: boolean;
28
+ };
29
+
30
+ type GetScreenParams = {
31
+ name: string;
32
+ projectId: string;
33
+ screenId: string;
34
+ };
35
+
36
+ type ContentItem = {
37
+ type: string;
38
+ [key: string]: any;
39
+ };
40
+
41
+ export const getScreenTool = (client: StitchMCPClient) => ({
42
+ name: "get_screen",
43
+ description:
44
+ "Retrieves and visually renders a specific screen within a Stitch project.",
45
+
46
+ parameters: {
47
+ type: "object",
48
+ properties: {
49
+ name: {
50
+ type: "string",
51
+ description:
52
+ "Required. Resource name. Format: projects/{project}/screens/{screen}"
53
+ },
54
+ projectId: {
55
+ type: "string",
56
+ description:
57
+ "Required (deprecated). Project ID without prefix."
58
+ },
59
+ screenId: {
60
+ type: "string",
61
+ description:
62
+ "Required (deprecated). Screen ID without prefix."
63
+ }
64
+ },
65
+ required: ["name", "projectId", "screenId"]
66
+ },
67
+
68
+ async execute(
69
+ _: string,
70
+ params: GetScreenParams
71
+ ) {
72
+ const { name, projectId, screenId } = params;
73
+
74
+ if (!name || !projectId || !screenId) {
75
+ throw new Error(
76
+ "name, projectId and screenId are required"
77
+ );
78
+ }
79
+
80
+ const screen = (await client.request("get_screen", {
81
+ name,
82
+ projectId,
83
+ screenId
84
+ })) as Screen;
85
+
86
+ const content: ContentItem[] = [];
87
+
88
+ content.push({
89
+ type: "text",
90
+ text: `## ${screen.title || "Untitled screen"}
91
+ Prompt: ${screen.prompt || "-"}
92
+ Device: ${screen.deviceType || "-"}
93
+ Size: ${screen.width || "?"} × ${screen.height || "?"}`
94
+ });
95
+
96
+ // Prefer embedded image
97
+ if (screen.screenshot?.fileContentBase64) {
98
+ const tempFilePath = path.join(
99
+ os.tmpdir(),
100
+ `stitch-screen-${Date.now()}.png`
101
+ );
102
+
103
+ fs.writeFileSync(
104
+ tempFilePath,
105
+ Buffer.from(
106
+ screen.screenshot.fileContentBase64,
107
+ "base64"
108
+ )
109
+ );
110
+
111
+ content.push({
112
+ type: "image",
113
+ path: tempFilePath,
114
+ caption: screen.title || "Generated screen"
115
+ });
116
+
117
+ return { content };
118
+ }
119
+
120
+ // Fallback remote image
121
+ if (screen.screenshot?.downloadUrl) {
122
+ content.push({
123
+ type: "image",
124
+ url: screen.screenshot.downloadUrl,
125
+ caption: screen.title || "Generated screen"
126
+ });
127
+
128
+ return { content };
129
+ }
130
+
131
+ // HTML fallback
132
+ if (screen.htmlCode?.fileContentBase64) {
133
+ const html = Buffer.from(
134
+ screen.htmlCode.fileContentBase64,
135
+ "base64"
136
+ ).toString("utf-8");
137
+
138
+ content.push({
139
+ type: "html",
140
+ html
141
+ });
142
+
143
+ return { content };
144
+ }
145
+
146
+ if (screen.htmlCode?.downloadUrl) {
147
+ content.push({
148
+ type: "html",
149
+ html: `<iframe
150
+ src="${screen.htmlCode.downloadUrl}"
151
+ style="width:100%;height:600px;border:none;"
152
+ ></iframe>`
153
+ });
154
+
155
+ return { content };
156
+ }
157
+
158
+ content.push({
159
+ type: "text",
160
+ text: "No visual preview available for this screen."
161
+ });
162
+
163
+ return { content };
164
+ }
165
+ });