@logictan/dsh-stitch-designer 2.0.4 → 2.1.0
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 +14 -5
- package/lib/canvas.js +30 -8
- package/lib/guidance.js +1 -1
- package/lib/index.js +25 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @logictan/dsh-stitch-designer
|
|
2
2
|
|
|
3
3
|
Google Stitch (AI UI generation) inside DSH: Stitch's own `mcp__stitch__*` tools,
|
|
4
|
-
one local addition (`
|
|
4
|
+
one local addition (`remove_screens_from_canvas`), plus the design conventions
|
|
5
5
|
that keep one code project bound to one Stitch project.
|
|
6
6
|
|
|
7
7
|
Ported from [liuxinlongwa-hue/dsh-stitch-designer](https://github.com/liuxinlongwa-hue/dsh-stitch-designer)
|
|
@@ -30,7 +30,7 @@ The tool list is read from Stitch at activation, not copied into this package,
|
|
|
30
30
|
so a tool Stitch adds or renames shows up without a code change. A call budget
|
|
31
31
|
of 180s covers `generate_screen_from_text`, which is long-running.
|
|
32
32
|
|
|
33
|
-
### `
|
|
33
|
+
### `remove_screens_from_canvas` — the one tool Stitch does not offer
|
|
34
34
|
|
|
35
35
|
Stitch has no screen-delete API. `stitch delete screen` answers
|
|
36
36
|
`UNSUPPORTED_RESOURCE / "Stitch screens do not support delete."`, and
|
|
@@ -40,8 +40,17 @@ either, so this is not a capability the bridge failed to expose.
|
|
|
40
40
|
|
|
41
41
|
What the service does accept is a project-level rewrite of the canvas:
|
|
42
42
|
`PATCH /v1/projects/<id>?updateMask=screenInstances` with the instance list
|
|
43
|
-
minus
|
|
44
|
-
small REST transport (`src/canvas.js`) alongside the MCP one.
|
|
43
|
+
minus the unwanted entries. That is what this tool does, and it is why the
|
|
44
|
+
plugin carries a small REST transport (`src/canvas.js`) alongside the MCP one.
|
|
45
|
+
|
|
46
|
+
Removal is **batch by construction, not by looping**: the canvas is a single
|
|
47
|
+
field, so N ids cost one GET and one PATCH. Looping would mean N
|
|
48
|
+
read-modify-write cycles and a lost removal whenever two of them raced. Passing
|
|
49
|
+
a single id in the list is simply the one-element case.
|
|
50
|
+
|
|
51
|
+
Ids that are not on the canvas do not fail the call: the ones that are get
|
|
52
|
+
removed, and the leftovers come back in the result so the caller can see them.
|
|
53
|
+
When *none* of the ids is on the canvas the tool raises instead of writing.
|
|
45
54
|
|
|
46
55
|
The screen object is not destroyed — it stays addressable at
|
|
47
56
|
`GET /v1/projects/<p>/screens/<s>` — but it leaves the project, which is what
|
|
@@ -50,7 +59,7 @@ route at all (the canvas `label` is a separate field and does not change the
|
|
|
50
59
|
screen `title`), so this plugin offers no rename tool.
|
|
51
60
|
|
|
52
61
|
```
|
|
53
|
-
|
|
62
|
+
mcp__stitch__remove_screens_from_canvas { projectId, screenIds: [screenId, ...] }
|
|
54
63
|
```
|
|
55
64
|
|
|
56
65
|
## Settings
|
package/lib/canvas.js
CHANGED
|
@@ -86,28 +86,48 @@ export function createCanvasClient(options = {}) {
|
|
|
86
86
|
|
|
87
87
|
return {
|
|
88
88
|
/**
|
|
89
|
-
* Take one
|
|
89
|
+
* Take one or more screens off a project's canvas.
|
|
90
|
+
*
|
|
91
|
+
* Batch is the primitive: the canvas is a single field, so every removal is
|
|
92
|
+
* absorbed into ONE read-modify-write cycle and therefore one PATCH, however
|
|
93
|
+
* many ids are given. Removing one screen is simply the one-element case.
|
|
90
94
|
*
|
|
91
95
|
* @param projectId - the project id (bare, without the `projects/` prefix).
|
|
92
|
-
* @param
|
|
96
|
+
* @param screenIds - screen ids to remove; the bare ids from `list_screens`.
|
|
93
97
|
* @param exec - the tool execution context, whose signal is honoured.
|
|
94
|
-
* @returns the project after the write
|
|
98
|
+
* @returns the project after the write, plus which ids were removed and
|
|
99
|
+
* which were not on the canvas.
|
|
100
|
+
* @throws when no id is given, or when none of them is on the canvas.
|
|
95
101
|
*/
|
|
96
|
-
async
|
|
102
|
+
async removeScreens(projectId, screenIds, exec) {
|
|
103
|
+
const requested = Array.isArray(screenIds) ? screenIds.filter((id) => typeof id === 'string' && id !== '') : [];
|
|
104
|
+
if (requested.length === 0) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
'No screen id was given: pass at least one screen id in screenIds. ' +
|
|
107
|
+
'Run list_screens to see the screens this project currently holds.',
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
97
111
|
const apiKey = await requireKey();
|
|
98
112
|
const projectUrl = `${url}/projects/${projectId}`;
|
|
99
113
|
|
|
100
114
|
const project = await request({ method: 'GET', url: projectUrl, apiKey, timeoutMs, signal: exec?.signal });
|
|
101
115
|
const instances = Array.isArray(project?.screenInstances) ? project.screenInstances : [];
|
|
102
|
-
const
|
|
103
|
-
|
|
116
|
+
const screenIdOf = (instance) => String(instance?.sourceScreen ?? '').split('/screens/').pop() ?? '';
|
|
117
|
+
|
|
118
|
+
const kept = instances.filter((instance) => !requested.includes(screenIdOf(instance)));
|
|
119
|
+
const present = instances.map(screenIdOf);
|
|
120
|
+
const removed = requested.filter((id) => present.includes(id));
|
|
121
|
+
const missing = requested.filter((id) => !present.includes(id));
|
|
122
|
+
|
|
123
|
+
if (removed.length === 0) {
|
|
104
124
|
throw new Error(
|
|
105
|
-
`
|
|
125
|
+
`None of the given screen ids is on the canvas of project ${projectId}, so there is nothing to remove. ` +
|
|
106
126
|
'Run list_screens to see the screens this project currently holds.',
|
|
107
127
|
);
|
|
108
128
|
}
|
|
109
129
|
|
|
110
|
-
|
|
130
|
+
const updated = await request({
|
|
111
131
|
method: 'PATCH',
|
|
112
132
|
url: `${projectUrl}?updateMask=screenInstances`,
|
|
113
133
|
apiKey,
|
|
@@ -115,6 +135,8 @@ export function createCanvasClient(options = {}) {
|
|
|
115
135
|
timeoutMs,
|
|
116
136
|
signal: exec?.signal,
|
|
117
137
|
});
|
|
138
|
+
|
|
139
|
+
return { ...updated, removed, missing };
|
|
118
140
|
},
|
|
119
141
|
};
|
|
120
142
|
}
|
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 界面设计):提供 Stitch 原生工具(数量随上游变化,含建/删/列项目、列/取界面、生成界面、改界面、生成变体、设计系统、设计稿上传与文件下载),以及 1 个本插件自建的 `
|
|
41
|
+
'本机已安装 dsh-stitch-designer 插件(Google Stitch AI 界面设计):提供 Stitch 原生工具(数量随上游变化,含建/删/列项目、列/取界面、生成界面、改界面、生成变体、设计系统、设计稿上传与文件下载),以及 1 个本插件自建的 `mcp__stitch__remove_screens_from_canvas`(把一张或多张 screen 从项目画布上移除;传一个 id 就是删一张——Stitch 没有删除单张 screen 的接口)。',
|
|
42
42
|
'',
|
|
43
43
|
'用 Stitch 设计稿实现界面时,遵守以下规范:',
|
|
44
44
|
'1. 一个代码项目只对应一个 Stitch 项目,对应关系记录在该代码项目根目录的 `.stitch.json`。继续沿用已记录的那个项目,不要为同一个代码项目再调 `create_project`——插件会直接报错拒绝,并告知已绑定的项目 id。记录指向的 Stitch 项目已被删除时,插件会自动清掉记录,可重新创建。',
|
package/lib/index.js
CHANGED
|
@@ -137,19 +137,23 @@ export function apply(ctx) {
|
|
|
137
137
|
sync().catch(report);
|
|
138
138
|
});
|
|
139
139
|
|
|
140
|
-
// `
|
|
140
|
+
// `remove_screens_from_canvas` is local, not upstream: Stitch has no
|
|
141
141
|
// screen-delete route (`stitch delete screen` answers
|
|
142
142
|
// `UNSUPPORTED_RESOURCE`, `DELETE .../screens/<id>` answers 404), so the
|
|
143
|
-
// bridge performs the removal itself through
|
|
143
|
+
// bridge performs the removal itself through one project-level PATCH. The
|
|
144
|
+
// tool takes a list because the canvas is one field: N removals are one
|
|
145
|
+
// write, and a single removal is just the one-element list. It is
|
|
144
146
|
// registered here unconditionally because it needs no `tools/list` to
|
|
145
147
|
// describe it — its contract is this file's.
|
|
146
148
|
const removeScreenDispose = tools.register({
|
|
147
|
-
name: publicToolName(SERVER_NAME, '
|
|
149
|
+
name: publicToolName(SERVER_NAME, 'remove_screens_from_canvas'),
|
|
148
150
|
description:
|
|
149
|
-
'Remove one
|
|
150
|
-
+ 'rewrites the project\'s canvas without
|
|
151
|
-
+ '
|
|
152
|
-
+ '
|
|
151
|
+
'Remove one or more screens from a Stitch project canvas. Stitch has no screen-delete API, so '
|
|
152
|
+
+ 'this rewrites the project\'s canvas without those screens — always in a single write, '
|
|
153
|
+
+ 'however many ids you pass. The screen objects themselves are not destroyed; they disappear '
|
|
154
|
+
+ 'from the project, which is what clears abandoned screens out. Use '
|
|
155
|
+
+ 'mcp__stitch__list_screens to find screen ids first. Ids that are not on the canvas are '
|
|
156
|
+
+ 'reported back rather than failing the whole call.',
|
|
153
157
|
parameters: {
|
|
154
158
|
type: 'object',
|
|
155
159
|
properties: {
|
|
@@ -157,25 +161,26 @@ export function apply(ctx) {
|
|
|
157
161
|
type: 'string',
|
|
158
162
|
description: 'Stitch project id (bare id, not "projects/<id>").',
|
|
159
163
|
},
|
|
160
|
-
|
|
161
|
-
type: '
|
|
162
|
-
|
|
164
|
+
screenIds: {
|
|
165
|
+
type: 'array',
|
|
166
|
+
items: { type: 'string' },
|
|
167
|
+
description: 'Ids of the screens to remove from the canvas. One id is the normal single-removal case.',
|
|
163
168
|
},
|
|
164
169
|
},
|
|
165
|
-
required: ['projectId', '
|
|
170
|
+
required: ['projectId', 'screenIds'],
|
|
166
171
|
},
|
|
167
172
|
output: createOutput(undefined),
|
|
168
173
|
async execute(args, exec) {
|
|
169
|
-
const result = await canvas.
|
|
174
|
+
const result = await canvas.removeScreens(args.projectId, args.screenIds, exec);
|
|
170
175
|
const remaining = Array.isArray(result?.screenInstances) ? result.screenInstances.length : 0;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
};
|
|
176
|
+
const lines = [
|
|
177
|
+
`Removed ${result.removed.length} screen(s) from project ${args.projectId}: ${result.removed.join(', ')}.`,
|
|
178
|
+
`The canvas now holds ${remaining} screen(s).`,
|
|
179
|
+
];
|
|
180
|
+
if (result.missing.length > 0) {
|
|
181
|
+
lines.push(`Not on the canvas (left alone): ${result.missing.join(', ')}.`);
|
|
182
|
+
}
|
|
183
|
+
return { content: [{ type: 'text', text: lines.join(' ') }] };
|
|
179
184
|
},
|
|
180
185
|
});
|
|
181
186
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logictan/dsh-stitch-designer",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
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",
|