@logictan/dsh-stitch-designer 2.0.3 → 2.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/README.md +29 -4
- package/lib/canvas.js +120 -0
- package/lib/guidance.js +1 -1
- package/lib/index.js +46 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# @logictan/dsh-stitch-designer
|
|
2
2
|
|
|
3
|
-
Google Stitch (AI UI generation) inside DSH:
|
|
4
|
-
|
|
3
|
+
Google Stitch (AI UI generation) inside DSH: Stitch's own `mcp__stitch__*` tools,
|
|
4
|
+
one local addition (`remove_screen_from_canvas`), plus the design conventions
|
|
5
|
+
that keep one code project bound to one Stitch project.
|
|
5
6
|
|
|
6
7
|
Ported from [liuxinlongwa-hue/dsh-stitch-designer](https://github.com/liuxinlongwa-hue/dsh-stitch-designer)
|
|
7
8
|
(MIT, © 2026 liuxinlongwa-hue). What changed here is the tool surface, the key
|
|
@@ -10,8 +11,9 @@ storage, and the scope — that project's preview panel, screenshot cache and
|
|
|
10
11
|
|
|
11
12
|
## What it gives the model
|
|
12
13
|
|
|
13
|
-
The
|
|
14
|
-
|
|
14
|
+
The Stitch tools the `mcp-stitch` MCP row used to expose (and whatever Stitch
|
|
15
|
+
has added since — `download_file` among them), under the same public names, so
|
|
16
|
+
existing prompts and habits keep working:
|
|
15
17
|
|
|
16
18
|
```
|
|
17
19
|
mcp__stitch__create_project mcp__stitch__get_project
|
|
@@ -28,6 +30,29 @@ The tool list is read from Stitch at activation, not copied into this package,
|
|
|
28
30
|
so a tool Stitch adds or renames shows up without a code change. A call budget
|
|
29
31
|
of 180s covers `generate_screen_from_text`, which is long-running.
|
|
30
32
|
|
|
33
|
+
### `remove_screen_from_canvas` — the one tool Stitch does not offer
|
|
34
|
+
|
|
35
|
+
Stitch has no screen-delete API. `stitch delete screen` answers
|
|
36
|
+
`UNSUPPORTED_RESOURCE / "Stitch screens do not support delete."`, and
|
|
37
|
+
`DELETE /projects/<p>/screens/<s>` answers 404 in every spelling including
|
|
38
|
+
`:delete` (measured 2026-11-08). The MCP tool list has no `delete_screen`
|
|
39
|
+
either, so this is not a capability the bridge failed to expose.
|
|
40
|
+
|
|
41
|
+
What the service does accept is a project-level rewrite of the canvas:
|
|
42
|
+
`PATCH /v1/projects/<id>?updateMask=screenInstances` with the instance list
|
|
43
|
+
minus one entry. That is what this tool does, and it is why the plugin carries a
|
|
44
|
+
small REST transport (`src/canvas.js`) alongside the MCP one.
|
|
45
|
+
|
|
46
|
+
The screen object is not destroyed — it stays addressable at
|
|
47
|
+
`GET /v1/projects/<p>/screens/<s>` — but it leaves the project, which is what
|
|
48
|
+
clears abandoned screens out of a project. Renaming a screen's title has no API
|
|
49
|
+
route at all (the canvas `label` is a separate field and does not change the
|
|
50
|
+
screen `title`), so this plugin offers no rename tool.
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
mcp__stitch__remove_screen_from_canvas { projectId, screenId }
|
|
54
|
+
```
|
|
55
|
+
|
|
31
56
|
## Settings
|
|
32
57
|
|
|
33
58
|
`Settings → Plugins → stitch-designer`:
|
package/lib/canvas.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport to Stitch's Canvas REST surface, for the one operation its MCP
|
|
3
|
+
* endpoint does not expose: taking a screen off a project's canvas.
|
|
4
|
+
*
|
|
5
|
+
* Stitch has no screen-delete route — `DELETE /projects/<p>/screens/<s>` answers
|
|
6
|
+
* 404 for every spelling including `:delete`, and the `@google/stitch` CLI
|
|
7
|
+
* rejects the command with `UNSUPPORTED_RESOURCE / "Stitch screens do not
|
|
8
|
+
* support delete."` (measured 2026-11-08). The MCP tool list has no
|
|
9
|
+
* `delete_screen` either, so this is not a field the bridge dropped.
|
|
10
|
+
*
|
|
11
|
+
* What the service DOES accept is a project-level PATCH of `screenInstances`:
|
|
12
|
+
* a project's canvas is a list of instances, each pointing at a `sourceScreen`,
|
|
13
|
+
* and writing that list back without one instance removes that screen from the
|
|
14
|
+
* canvas. Measured against project 4697019860827468919: the PATCH returned 200
|
|
15
|
+
* and the project went from five screens to three.
|
|
16
|
+
*
|
|
17
|
+
* Two properties of that endpoint shape this module:
|
|
18
|
+
*
|
|
19
|
+
* - **The list is replaced whole** (`updateMask=screenInstances`), so every
|
|
20
|
+
* surviving instance is sent back verbatim. A field dropped here is a lost
|
|
21
|
+
* canvas position, and the API will not complain.
|
|
22
|
+
* - **The instance id is not the screen id.** A generated screen reuses its id
|
|
23
|
+
* as the instance id, but an uploaded image gets a fresh UUID instance whose
|
|
24
|
+
* `sourceScreen` ends in the screen id. Matching goes through `sourceScreen`,
|
|
25
|
+
* which is correct for both shapes.
|
|
26
|
+
*
|
|
27
|
+
* The screen object itself survives the removal: `GET .../screens/<id>` still
|
|
28
|
+
* answers afterwards. That is the service's model, not a shortfall here — the
|
|
29
|
+
* complaint this addresses is a project canvas full of abandoned screens.
|
|
30
|
+
*
|
|
31
|
+
* @module @logictan/dsh-stitch-designer/canvas
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/** Stitch's Canvas REST base. Distinct from the MCP endpoint in `stitch.js`. */
|
|
35
|
+
export const CANVAS_API_URL = 'https://stitch.googleapis.com/v1';
|
|
36
|
+
|
|
37
|
+
/** Budget for one Canvas round trip; both calls here are small. */
|
|
38
|
+
export const DEFAULT_CANVAS_TIMEOUT_MS = 60_000;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* One Canvas REST round trip.
|
|
42
|
+
*
|
|
43
|
+
* @param options - method, url, per-call key, body, timeout and abort signal.
|
|
44
|
+
* @returns the parsed JSON response.
|
|
45
|
+
* @throws when the request fails or the response is not JSON.
|
|
46
|
+
*/
|
|
47
|
+
async function request(options) {
|
|
48
|
+
const { method, url, apiKey, body, timeoutMs, signal } = options;
|
|
49
|
+
const response = await fetch(url, {
|
|
50
|
+
method,
|
|
51
|
+
headers: {
|
|
52
|
+
'X-Goog-Api-Key': apiKey,
|
|
53
|
+
...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
|
|
54
|
+
},
|
|
55
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
56
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)].filter(Boolean)),
|
|
57
|
+
});
|
|
58
|
+
if (!response.ok) {
|
|
59
|
+
const detail = await response.text().catch(() => '');
|
|
60
|
+
throw new Error(`Stitch ${method} ${url} failed: HTTP ${response.status}${detail ? ` ${detail.slice(0, 300)}` : ''}`);
|
|
61
|
+
}
|
|
62
|
+
return response.json();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Build a Canvas client bound to one key-resolution callback.
|
|
67
|
+
*
|
|
68
|
+
* The key is resolved per call for the same reason as in `stitch.js`: it can be
|
|
69
|
+
* replaced from the Plugins page while the process runs.
|
|
70
|
+
*
|
|
71
|
+
* @param options - key resolver, base URL override and per-call timeout.
|
|
72
|
+
* @returns `removeScreen`.
|
|
73
|
+
*/
|
|
74
|
+
export function createCanvasClient(options = {}) {
|
|
75
|
+
const { resolveApiKey, url = CANVAS_API_URL, timeoutMs = DEFAULT_CANVAS_TIMEOUT_MS } = options;
|
|
76
|
+
|
|
77
|
+
const requireKey = async () => {
|
|
78
|
+
const apiKey = await resolveApiKey();
|
|
79
|
+
if (typeof apiKey !== 'string' || apiKey === '') {
|
|
80
|
+
throw new Error(
|
|
81
|
+
'Stitch API key is not configured. Open Settings → Plugins → stitch-designer and paste a key from https://stitch.withgoogle.com (avatar → Stitch Settings → API key).',
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return apiKey;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
/**
|
|
89
|
+
* Take one screen off a project's canvas.
|
|
90
|
+
*
|
|
91
|
+
* @param projectId - the project id (bare, without the `projects/` prefix).
|
|
92
|
+
* @param screenId - the screen id to remove; the bare id from `list_screens`.
|
|
93
|
+
* @param exec - the tool execution context, whose signal is honoured.
|
|
94
|
+
* @returns the project after the write.
|
|
95
|
+
*/
|
|
96
|
+
async removeScreen(projectId, screenId, exec) {
|
|
97
|
+
const apiKey = await requireKey();
|
|
98
|
+
const projectUrl = `${url}/projects/${projectId}`;
|
|
99
|
+
|
|
100
|
+
const project = await request({ method: 'GET', url: projectUrl, apiKey, timeoutMs, signal: exec?.signal });
|
|
101
|
+
const instances = Array.isArray(project?.screenInstances) ? project.screenInstances : [];
|
|
102
|
+
const kept = instances.filter((instance) => !String(instance?.sourceScreen ?? '').endsWith(`/screens/${screenId}`));
|
|
103
|
+
if (kept.length === instances.length) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`Screen ${screenId} is not on the canvas of project ${projectId}, so there is nothing to remove. ` +
|
|
106
|
+
'Run list_screens to see the screens this project currently holds.',
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return request({
|
|
111
|
+
method: 'PATCH',
|
|
112
|
+
url: `${projectUrl}?updateMask=screenInstances`,
|
|
113
|
+
apiKey,
|
|
114
|
+
body: { screenInstances: kept },
|
|
115
|
+
timeoutMs,
|
|
116
|
+
signal: exec?.signal,
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
package/lib/guidance.js
CHANGED
|
@@ -38,7 +38,7 @@ export const SECTION_ORDER = 150;
|
|
|
38
38
|
* acted on.
|
|
39
39
|
*/
|
|
40
40
|
export const STITCH_GUIDANCE = [
|
|
41
|
-
'本机已安装 dsh-stitch-designer 插件(Google Stitch AI 界面设计):提供
|
|
41
|
+
'本机已安装 dsh-stitch-designer 插件(Google Stitch AI 界面设计):提供 Stitch 原生工具(数量随上游变化,含建/删/列项目、列/取界面、生成界面、改界面、生成变体、设计系统、设计稿上传与文件下载),以及 1 个本插件自建的 `mcp__stitch__remove_screen_from_canvas`(把某张 screen 从项目画布上移除——Stitch 没有删除单张 screen 的接口)。',
|
|
42
42
|
'',
|
|
43
43
|
'用 Stitch 设计稿实现界面时,遵守以下规范:',
|
|
44
44
|
'1. 一个代码项目只对应一个 Stitch 项目,对应关系记录在该代码项目根目录的 `.stitch.json`。继续沿用已记录的那个项目,不要为同一个代码项目再调 `create_project`——插件会直接报错拒绝,并告知已绑定的项目 id。记录指向的 Stitch 项目已被删除时,插件会自动清掉记录,可重新创建。',
|
package/lib/index.js
CHANGED
|
@@ -37,10 +37,11 @@
|
|
|
37
37
|
*
|
|
38
38
|
* @module @logictan/dsh-stitch-designer
|
|
39
39
|
*/
|
|
40
|
+
import { createCanvasClient } from './canvas.js';
|
|
40
41
|
import { createStitchClient } from './stitch.js';
|
|
41
42
|
import { createInvoker } from './conventions.js';
|
|
42
43
|
import { SECTION_NAME, SECTION_ORDER, STITCH_GUIDANCE } from './guidance.js';
|
|
43
|
-
import { createToolDefinition, publicToolName } from './tools.js';
|
|
44
|
+
import { createOutput, createToolDefinition, publicToolName } from './tools.js';
|
|
44
45
|
|
|
45
46
|
/** Plugin row id; must equal the row id in `cordis.patch.yml`. */
|
|
46
47
|
export const name = 'stitch-designer';
|
|
@@ -80,6 +81,7 @@ export function apply(ctx) {
|
|
|
80
81
|
};
|
|
81
82
|
|
|
82
83
|
const stitch = createStitchClient({ resolveApiKey });
|
|
84
|
+
const canvas = createCanvasClient({ resolveApiKey });
|
|
83
85
|
|
|
84
86
|
// One code project ↔ one Stitch project is enforced here rather than merely
|
|
85
87
|
// announced: this wrapper is the only seam that sees which code project a
|
|
@@ -135,9 +137,52 @@ export function apply(ctx) {
|
|
|
135
137
|
sync().catch(report);
|
|
136
138
|
});
|
|
137
139
|
|
|
140
|
+
// `remove_screen_from_canvas` is local, not upstream: Stitch has no
|
|
141
|
+
// screen-delete route (`stitch delete screen` answers
|
|
142
|
+
// `UNSUPPORTED_RESOURCE`, `DELETE .../screens/<id>` answers 404), so the
|
|
143
|
+
// bridge performs the removal itself through a project-level PATCH. It is
|
|
144
|
+
// registered here unconditionally because it needs no `tools/list` to
|
|
145
|
+
// describe it — its contract is this file's.
|
|
146
|
+
const removeScreenDispose = tools.register({
|
|
147
|
+
name: publicToolName(SERVER_NAME, 'remove_screen_from_canvas'),
|
|
148
|
+
description:
|
|
149
|
+
'Remove one screen from a Stitch project canvas. Stitch has no screen-delete API, so this '
|
|
150
|
+
+ 'rewrites the project\'s canvas without that screen. The screen object itself is not '
|
|
151
|
+
+ 'destroyed; it disappears from the project — which is what clears abandoned screens out '
|
|
152
|
+
+ 'of a project. Use mcp__stitch__list_screens to find the screen id first.',
|
|
153
|
+
parameters: {
|
|
154
|
+
type: 'object',
|
|
155
|
+
properties: {
|
|
156
|
+
projectId: {
|
|
157
|
+
type: 'string',
|
|
158
|
+
description: 'Stitch project id (bare id, not "projects/<id>").',
|
|
159
|
+
},
|
|
160
|
+
screenId: {
|
|
161
|
+
type: 'string',
|
|
162
|
+
description: 'Id of the screen to remove from the canvas.',
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
required: ['projectId', 'screenId'],
|
|
166
|
+
},
|
|
167
|
+
output: createOutput(undefined),
|
|
168
|
+
async execute(args, exec) {
|
|
169
|
+
const result = await canvas.removeScreen(args.projectId, args.screenId, exec);
|
|
170
|
+
const remaining = Array.isArray(result?.screenInstances) ? result.screenInstances.length : 0;
|
|
171
|
+
return {
|
|
172
|
+
content: [
|
|
173
|
+
{
|
|
174
|
+
type: 'text',
|
|
175
|
+
text: `Removed screen ${args.screenId} from project ${args.projectId}. The canvas now holds ${remaining} screen(s).`,
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
138
182
|
return () => {
|
|
139
183
|
disposed = true;
|
|
140
184
|
offCredential();
|
|
185
|
+
removeScreenDispose();
|
|
141
186
|
for (const dispose of disposers) dispose();
|
|
142
187
|
disposers = [];
|
|
143
188
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logictan/dsh-stitch-designer",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "DSH Stitch designer: Google Stitch AI UI generation as native mcp__stitch__* tools, plus the design conventions that keep one code project bound to one Stitch project. DSH Stitch 界面设计子插件。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|