@logictan/dsh-stitch-designer 1.0.0 → 2.0.1
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 +47 -28
- package/lib/client.js +39 -355
- package/lib/conventions.js +116 -0
- package/lib/guidance.js +54 -0
- package/lib/index.js +42 -28
- package/lib/project.js +77 -0
- package/package.json +11 -5
- package/lib/routes.js +0 -250
- package/lib/store.js +0 -229
package/README.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
# @logictan/dsh-stitch-designer
|
|
2
2
|
|
|
3
3
|
Google Stitch (AI UI generation) inside DSH: the 15 `mcp__stitch__*` tools, plus
|
|
4
|
-
|
|
5
|
-
screenshot/HTML cache, and exports the 1:1 HTML source.
|
|
4
|
+
the design conventions that keep one code project bound to one Stitch project.
|
|
6
5
|
|
|
7
6
|
Ported from [liuxinlongwa-hue/dsh-stitch-designer](https://github.com/liuxinlongwa-hue/dsh-stitch-designer)
|
|
8
|
-
(MIT, © 2026 liuxinlongwa-hue)
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
(MIT, © 2026 liuxinlongwa-hue). What changed here is the tool surface, the key
|
|
8
|
+
storage, and the scope — that project's preview panel, screenshot cache and
|
|
9
|
+
1:1 HTML export endpoint have been removed; see below.
|
|
11
10
|
|
|
12
11
|
## What it gives the model
|
|
13
12
|
|
|
@@ -44,41 +43,61 @@ in a plugin config row, so it never appears in plaintext in
|
|
|
44
43
|
|
|
45
44
|
Setting the key registers the tools immediately; no restart is needed.
|
|
46
45
|
|
|
47
|
-
##
|
|
46
|
+
## Design conventions
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
thumbnail strip, and **导出 1:1 HTML 源码**.
|
|
48
|
+
Two groups of rules apply: how a screen is commissioned, and how it is then
|
|
49
|
+
implemented.
|
|
52
50
|
|
|
53
|
-
|
|
54
|
-
calls `generate_screen_from_text`; ask for a change, and it calls
|
|
55
|
-
`edit_screens`. Then press **刷新** in the panel.
|
|
51
|
+
Commissioning:
|
|
56
52
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
| Rule | Why |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| Say what it should look like and what it must show; put no other limits on it | A brief that fixes layout, spacing and colour turns design into transcription, and the result is no better than writing it by hand. |
|
|
56
|
+
| Ask for nothing that cannot be built | The screen is going to be reproduced pixel for pixel, so a wish for an impossible interaction or unavailable data is a defect in the brief. |
|
|
57
|
+
| Follow the project's existing design language | Screens in this repository follow `@logictan/dsh-macos-theme` unless told otherwise. A second visual language cannot be implemented without a rewrite. |
|
|
58
|
+
| Compose it from components the project already has | Host components and the shared component layer exist; a redrawn lookalike is work spent twice. |
|
|
59
|
+
| Ask for a dark variant every time | Dark is the same design language's dark values, not an inversion. Both are implemented from one set of tokens. |
|
|
62
60
|
|
|
63
|
-
|
|
61
|
+
Implementation:
|
|
64
62
|
|
|
65
|
-
|
|
63
|
+
| Rule | How it reaches the model |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| One code project owns exactly one Stitch project | **Enforced.** The id is recorded in the code project's `.stitch.json`; a second `create_project` from an already-bound directory is refused with the existing id. |
|
|
66
|
+
| Implement with TailwindCSS, the way Stitch builds its screens | Announced in the system prompt. Unless the repository already has an architecture that cannot accommodate TailwindCSS, in which case the model is told to explain that first. |
|
|
67
|
+
| Implement from Stitch's exported HTML for pixel-level fidelity | Announced in the system prompt. The export goes to `<project>/docs/design/<screenId>.html`; anywhere the implementation would differ from the design, the model is told to ask first and give the reason. |
|
|
68
|
+
|
|
69
|
+
Only the one-project rule is enforced in code, because it is the only one with a
|
|
70
|
+
computable predicate. "Did you use TailwindCSS?" and "is this pixel-perfect?"
|
|
71
|
+
cannot be checked, so a validator for them would be a lie — they are delivered
|
|
72
|
+
the way this repository delivers every other non-computable rule, as a
|
|
73
|
+
system-prompt section the plugin registers itself (`src/guidance.js`).
|
|
74
|
+
|
|
75
|
+
`.stitch.json` is the project's own file — commit it. It is small and
|
|
76
|
+
hand-editable on purpose: it is the escape hatch when a Stitch project was
|
|
77
|
+
deleted, or when the wrong one was recorded. A record pointing at a project
|
|
78
|
+
that no longer exists is cleared automatically rather than obeyed, so the
|
|
79
|
+
refusal can never become a permanent dead end; `delete_project` clears it too.
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{ "projectId": "15445722684773602632" }
|
|
83
|
+
```
|
|
66
84
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
| GET | `/stitch/api/html/<screenId>` | Fetch and cache a screen's 1:1 HTML, returning its local URL |
|
|
71
|
-
| GET | `/stitch/screens/<screenId>.png` | Cached screenshot |
|
|
72
|
-
| GET | `/stitch/html/<screenId>.html` | Exported HTML source |
|
|
85
|
+
Only the id is stored. The title is not, because it is a second copy of a fact
|
|
86
|
+
Stitch already owns and would go stale as soon as the project is renamed
|
|
87
|
+
upstream — while the binding rule reads the id alone.
|
|
73
88
|
|
|
74
89
|
## Local files
|
|
75
90
|
|
|
76
91
|
| Path | Contents |
|
|
77
92
|
| --- | --- |
|
|
78
93
|
| `$DSH_HOME/.credentials.yaml` | The API key, under `STITCH_API_KEY` |
|
|
79
|
-
|
|
|
80
|
-
|
|
81
|
-
|
|
94
|
+
| `<project>/.stitch.json` | The Stitch project this code project owns (see above) |
|
|
95
|
+
|
|
96
|
+
`~/.stitch` — the previous generation's screenshot/HTML cache under the user's
|
|
97
|
+
home directory — is no longer written or read by this plugin. Exporting a
|
|
98
|
+
design to `<project>/docs/design/` is the model following the announced
|
|
99
|
+
convention, not a plugin action; it travels with the repository, so a later
|
|
100
|
+
session or a teammate can read the design the code was built from.
|
|
82
101
|
|
|
83
102
|
## Replacing the `mcp-stitch` row
|
|
84
103
|
|
package/lib/client.js
CHANGED
|
@@ -1,30 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Browser half: the
|
|
2
|
+
* Browser half: the API-key card on the plugin's Plugins-page row.
|
|
3
3
|
*
|
|
4
4
|
* This file is already in the client module loader's protocol — it is not a
|
|
5
5
|
* module and imports nothing. `build.mjs` copies it to `lib/client.js`
|
|
6
6
|
* verbatim, which is why `package.json` exports `./client` at that path.
|
|
7
7
|
*
|
|
8
|
-
* Two independent surfaces share this bundle:
|
|
9
|
-
*
|
|
10
|
-
* - the preview panel, registered into `conversation.session.header.actions`;
|
|
11
|
-
* - the API-key card, registered into `plugins.row.config` under
|
|
12
|
-
* `<bundle>#stitch-designer`.
|
|
13
|
-
*
|
|
14
8
|
* `remote.credentials` is injected NESTED inside the card registration rather
|
|
15
9
|
* than declared in this plugin's `inject` list. A plugin that waits on a
|
|
16
|
-
* service its host does not provide never activates at all,
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* The panel's HTTP contract is `src/routes.js`: `GET /stitch/api/state` and
|
|
21
|
-
* `GET /stitch/api/html/<id>`, plus the cached `/stitch/screens/*.png` and
|
|
22
|
-
* `/stitch/html/*.html` files.
|
|
10
|
+
* service its host does not provide never activates at all, so a declared
|
|
11
|
+
* dependency would turn "this host has no credential provider" into "the whole
|
|
12
|
+
* browser half is gone".
|
|
23
13
|
*/
|
|
24
14
|
window.__ModuleLoader__.load({
|
|
25
15
|
id: "@logictan/dsh-stitch-designer",
|
|
26
16
|
factory: function (require) {
|
|
27
17
|
var React = require("react");
|
|
18
|
+
var UI = require("@logictan/dsh-plugins-shared-client");
|
|
28
19
|
|
|
29
20
|
/** Loader entry id this card's row is keyed by; equals the host half's `export const name`. */
|
|
30
21
|
var ROW_ID = "stitch-designer";
|
|
@@ -50,308 +41,6 @@ window.__ModuleLoader__.load({
|
|
|
50
41
|
*/
|
|
51
42
|
var API_KEY_REF = "STITCH_API_KEY";
|
|
52
43
|
|
|
53
|
-
var CSS_ID = "stitch-designer/panel.css";
|
|
54
|
-
var css = [
|
|
55
|
-
".std-root{position:relative;display:inline-flex;align-items:center}",
|
|
56
|
-
".std-trigger{min-height:28px;display:inline-flex;align-items:center;gap:6px;padding:3px 10px;border-radius:6px;border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3));background:transparent;color:var(--dsw-alias-label-secondary, inherit);font-size:12px;line-height:18px;cursor:pointer}",
|
|
57
|
-
".std-trigger:hover,.std-trigger:focus-visible{color:var(--dsw-alias-label-primary, inherit);background:var(--dsw-alias-fill-l2, rgba(128,128,128,.08))}",
|
|
58
|
-
".std-dot{width:8px;height:8px;border-radius:50%;background:linear-gradient(135deg,#4285F4,#34A853);flex:none}",
|
|
59
|
-
".std-panel{position:fixed;top:calc(var(--dsw-header-h, 48px) + 8px);right:16px;z-index:1000;width:min(460px, calc(100vw - 32px));max-height:min(680px, calc(100vh - 96px));display:flex;flex-direction:column;background:var(--dsw-specific-menu, #1b1b1f);border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.35));border-radius:12px;box-shadow:var(--dsw-shadow-lv3, 0 8px 30px rgba(0,0,0,.35));overflow:hidden}",
|
|
60
|
-
".std-head{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:8px 12px;border-bottom:1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.2));font-size:13px;font-weight:600}",
|
|
61
|
-
".std-head-actions{display:flex;gap:6px;align-items:center}",
|
|
62
|
-
".std-btn{padding:2px 8px;border-radius:6px;border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3));background:transparent;color:var(--dsw-alias-label-tertiary, inherit);font-size:12px;cursor:pointer}",
|
|
63
|
-
".std-btn:hover{color:var(--dsw-alias-label-primary, inherit)}",
|
|
64
|
-
".std-btn:disabled{opacity:.5;cursor:default}",
|
|
65
|
-
".std-select{padding:3px 8px;border-radius:6px;border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3));background:var(--dsw-specific-menu, #1b1b1f);color:var(--dsw-alias-label-primary, inherit);font-size:12px;line-height:18px;max-width:100%}",
|
|
66
|
-
".std-body{overflow:auto;padding:10px 12px;display:flex;flex-direction:column;gap:10px;--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2, rgba(128,128,128,.4))}",
|
|
67
|
-
".std-meta{font-size:11px;color:var(--dsw-alias-label-tertiary, inherit);display:flex;gap:10px;flex-wrap:wrap;padding:0 2px}",
|
|
68
|
-
".std-tag{padding:1px 8px;border-radius:99px;background:var(--dsw-alias-fill-l2, rgba(128,128,128,.1));font-size:11px;color:var(--dsw-alias-label-secondary, inherit)}",
|
|
69
|
-
".std-img-wrap{display:flex;justify-content:center;background:var(--dsw-alias-fill-l2, rgba(128,128,128,.06));border-radius:10px;padding:8px;min-height:120px}",
|
|
70
|
-
".std-img{max-width:100%;max-height:min(480px, calc(100vh - 240px));border-radius:6px;box-shadow:0 4px 16px rgba(0,0,0,.25)}",
|
|
71
|
-
".std-thumbs{display:flex;gap:8px;overflow-x:auto;padding:2px 0;--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2, rgba(128,128,128,.4))}",
|
|
72
|
-
".std-thumb{width:56px;height:96px;object-fit:cover;border-radius:6px;border:2px solid transparent;cursor:pointer;flex:none;opacity:.75;transition:opacity .15s}",
|
|
73
|
-
".std-thumb:hover{opacity:1}",
|
|
74
|
-
".std-thumb-on{border-color:var(--dsw-alias-accent, #4285F4);opacity:1}",
|
|
75
|
-
".std-empty{padding:26px 12px;text-align:center;color:var(--dsw-alias-label-tertiary, inherit);font-size:13px;line-height:1.6}",
|
|
76
|
-
".std-hint{padding:8px 10px;border-radius:8px;background:var(--dsw-alias-fill-l2, rgba(128,128,128,.07));font-size:12px;color:var(--dsw-alias-label-secondary, inherit);line-height:1.6}",
|
|
77
|
-
".std-err{padding:10px 12px;text-align:center;color:var(--dsw-alias-danger-fg, #ef4444);font-size:12px}",
|
|
78
|
-
".std-card{display:flex;flex-direction:column;gap:10px;padding:4px 0;font-size:13px}",
|
|
79
|
-
".std-card-row{display:flex;align-items:center;gap:8px}",
|
|
80
|
-
".std-input{flex:1;min-width:0;padding:5px 8px;border-radius:6px;border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.35));background:var(--dsw-alias-fill-l1, transparent);color:var(--dsw-alias-label-primary, inherit);font-size:12px;line-height:18px}",
|
|
81
|
-
".std-note{font-size:12px;line-height:1.6;color:var(--dsw-alias-label-tertiary, inherit)}",
|
|
82
|
-
".std-ok{color:var(--dsw-alias-success-fg, #22c55e)}",
|
|
83
|
-
".std-bad{color:var(--dsw-alias-danger-fg, #ef4444)}"
|
|
84
|
-
].join("");
|
|
85
|
-
|
|
86
|
-
if (typeof document !== "undefined" && document.querySelector('style[data-plugin-css="' + CSS_ID + '"]') === null) {
|
|
87
|
-
var tag = document.createElement("style");
|
|
88
|
-
tag.dataset.plugin = "stitch-designer";
|
|
89
|
-
tag.dataset.pluginCss = CSS_ID;
|
|
90
|
-
tag.textContent = css;
|
|
91
|
-
document.head.appendChild(tag);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
//#region preview panel
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* The session-header Stitch preview panel.
|
|
98
|
-
*
|
|
99
|
-
* Reads `GET /stitch/api/state` and renders the newest cached screenshot,
|
|
100
|
-
* a project picker, and a thumbnail strip. The Host does the caching and the
|
|
101
|
-
* index-lag fallback; this half only presents what it is given.
|
|
102
|
-
*/
|
|
103
|
-
function DesignerPanel() {
|
|
104
|
-
var open = React.useState(false);
|
|
105
|
-
var opened = open[0];
|
|
106
|
-
var setOpened = open[1];
|
|
107
|
-
var state = React.useState(null);
|
|
108
|
-
var data = state[0];
|
|
109
|
-
var setData = state[1];
|
|
110
|
-
var err = React.useState("");
|
|
111
|
-
var errorText = err[0];
|
|
112
|
-
var setErr = err[1];
|
|
113
|
-
var sel = React.useState("");
|
|
114
|
-
var selectedId = sel[0];
|
|
115
|
-
var setSelectedId = sel[1];
|
|
116
|
-
var idx = React.useState(0);
|
|
117
|
-
var currentIdx = idx[0];
|
|
118
|
-
var setCurrentIdx = idx[1];
|
|
119
|
-
var busy = React.useState(false);
|
|
120
|
-
var loading = busy[0];
|
|
121
|
-
var setLoading = busy[1];
|
|
122
|
-
|
|
123
|
-
function refresh(projectId) {
|
|
124
|
-
setErr("");
|
|
125
|
-
setLoading(true);
|
|
126
|
-
var q = projectId ? "?projectId=" + encodeURIComponent(projectId) : "";
|
|
127
|
-
fetch("/stitch/api/state" + q, { cache: "no-store" })
|
|
128
|
-
.then(function (r) {
|
|
129
|
-
if (!r.ok) throw new Error("HTTP " + r.status);
|
|
130
|
-
return r.json();
|
|
131
|
-
})
|
|
132
|
-
.then(function (d) {
|
|
133
|
-
if (d.ok) {
|
|
134
|
-
setData(d);
|
|
135
|
-
setCurrentIdx(0);
|
|
136
|
-
} else {
|
|
137
|
-
setErr(d.error || "未知错误");
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
.catch(function (e) {
|
|
141
|
-
setErr((e && e.message) || String(e));
|
|
142
|
-
})
|
|
143
|
-
.then(function () {
|
|
144
|
-
setLoading(false);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function toggle() {
|
|
149
|
-
var next = !opened;
|
|
150
|
-
setOpened(next);
|
|
151
|
-
if (next) refresh(selectedId || (data && data.projectId));
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function onProjectChange(e) {
|
|
155
|
-
var id = e.target.value;
|
|
156
|
-
setSelectedId(id);
|
|
157
|
-
setCurrentIdx(0);
|
|
158
|
-
refresh(id);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function exportHtml(screenId) {
|
|
162
|
-
fetch("/stitch/api/html/" + screenId, { cache: "no-store" })
|
|
163
|
-
.then(function (r) {
|
|
164
|
-
if (!r.ok) throw new Error("HTTP " + r.status);
|
|
165
|
-
return r.json();
|
|
166
|
-
})
|
|
167
|
-
.then(function (d) {
|
|
168
|
-
if (d.ok && d.html) window.open(d.html, "_blank");
|
|
169
|
-
else alert("导出失败: " + (d.error || "未知错误"));
|
|
170
|
-
})
|
|
171
|
-
.catch(function (e) {
|
|
172
|
-
alert("导出失败: " + ((e && e.message) || e));
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
var trigger = React.createElement(
|
|
177
|
-
"button",
|
|
178
|
-
{
|
|
179
|
-
className: "std-trigger",
|
|
180
|
-
title: "AI 设计(Stitch 预览)",
|
|
181
|
-
"aria-label": "AI 设计预览",
|
|
182
|
-
"aria-expanded": opened,
|
|
183
|
-
onClick: toggle,
|
|
184
|
-
},
|
|
185
|
-
React.createElement("span", { className: "std-dot" }),
|
|
186
|
-
"AI 设计",
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
var body;
|
|
190
|
-
if (opened) {
|
|
191
|
-
if (errorText) {
|
|
192
|
-
body = React.createElement("div", { className: "std-err" }, "加载失败: " + errorText);
|
|
193
|
-
} else if (data === null) {
|
|
194
|
-
body = React.createElement("div", { className: "std-empty" }, "加载中…");
|
|
195
|
-
} else {
|
|
196
|
-
var projectOptions = (data.projects || []).map(function (p) {
|
|
197
|
-
return React.createElement(
|
|
198
|
-
"option",
|
|
199
|
-
{ key: p.id, value: p.id },
|
|
200
|
-
(p.title || "项目 " + String(p.id).slice(-6)) + (p.id === data.projectId ? " ✓" : ""),
|
|
201
|
-
);
|
|
202
|
-
});
|
|
203
|
-
var projectPicker = React.createElement(
|
|
204
|
-
"div",
|
|
205
|
-
{ className: "std-meta", style: { alignItems: "center", gap: 6 } },
|
|
206
|
-
React.createElement("span", { className: "std-tag" }, "项目"),
|
|
207
|
-
React.createElement(
|
|
208
|
-
"select",
|
|
209
|
-
{
|
|
210
|
-
className: "std-select",
|
|
211
|
-
value: selectedId || data.projectId || "",
|
|
212
|
-
onChange: onProjectChange,
|
|
213
|
-
style: { flex: 1, minWidth: 0 },
|
|
214
|
-
},
|
|
215
|
-
React.createElement("option", { value: "" }, "选择项目…"),
|
|
216
|
-
projectOptions,
|
|
217
|
-
),
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
var screens = data.screens || [];
|
|
221
|
-
var total = screens.length;
|
|
222
|
-
var cur = currentIdx < total ? screens[currentIdx] : screens[0];
|
|
223
|
-
var meta = React.createElement(
|
|
224
|
-
"div",
|
|
225
|
-
{ className: "std-meta" },
|
|
226
|
-
React.createElement("span", { className: "std-tag" }, data.projectTitle || "项目 " + String(data.projectId || "").slice(-6)),
|
|
227
|
-
total > 0 ? React.createElement("span", { className: "std-tag" }, "共 " + total + " 张") : null,
|
|
228
|
-
cur ? React.createElement("span", { className: "std-tag" }, cur.deviceType || "MOBILE") : null,
|
|
229
|
-
cur ? React.createElement("span", { className: "std-tag" }, (cur.width || "") + "×" + (cur.height || "")) : null,
|
|
230
|
-
cur && cur.title ? React.createElement("span", { className: "std-tag" }, cur.title) : null,
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
var preview;
|
|
234
|
-
if (cur && cur.preview) {
|
|
235
|
-
preview = React.createElement(
|
|
236
|
-
"div",
|
|
237
|
-
{ className: "std-img-wrap" },
|
|
238
|
-
React.createElement("img", {
|
|
239
|
-
className: "std-img",
|
|
240
|
-
src: cur.preview + "?t=" + Date.now(),
|
|
241
|
-
alt: "设计预览",
|
|
242
|
-
onClick: function () {
|
|
243
|
-
window.open(cur.preview, "_blank");
|
|
244
|
-
},
|
|
245
|
-
}),
|
|
246
|
-
);
|
|
247
|
-
} else {
|
|
248
|
-
preview = React.createElement(
|
|
249
|
-
"div",
|
|
250
|
-
{ className: "std-empty" },
|
|
251
|
-
"该项目还没有设计。在对话里告诉我需求(如:帮我设计一个回收小程序首页,APP 端)→ 生成后这里实时预览。或在上方切换查看其他项目。",
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
var thumbs = null;
|
|
256
|
-
if (total > 1) {
|
|
257
|
-
thumbs = React.createElement(
|
|
258
|
-
"div",
|
|
259
|
-
{ className: "std-thumbs" },
|
|
260
|
-
screens.map(function (s, i) {
|
|
261
|
-
return React.createElement("img", {
|
|
262
|
-
key: s.id || i,
|
|
263
|
-
className: "std-thumb" + (i === currentIdx ? " std-thumb-on" : ""),
|
|
264
|
-
src: s.preview + "?t=" + Date.now(),
|
|
265
|
-
alt: s.title || "设计 " + (i + 1),
|
|
266
|
-
onClick: function () {
|
|
267
|
-
setCurrentIdx(i);
|
|
268
|
-
},
|
|
269
|
-
});
|
|
270
|
-
}),
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
var actions = null;
|
|
275
|
-
if (cur) {
|
|
276
|
-
actions = React.createElement(
|
|
277
|
-
"div",
|
|
278
|
-
{ className: "std-meta", style: { marginTop: 4 } },
|
|
279
|
-
React.createElement(
|
|
280
|
-
"button",
|
|
281
|
-
{
|
|
282
|
-
className: "std-btn",
|
|
283
|
-
onClick: function () {
|
|
284
|
-
exportHtml(cur.id);
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
"📄 导出 1:1 HTML 源码",
|
|
288
|
-
),
|
|
289
|
-
React.createElement(
|
|
290
|
-
"button",
|
|
291
|
-
{
|
|
292
|
-
className: "std-btn",
|
|
293
|
-
onClick: function () {
|
|
294
|
-
window.open(cur.preview, "_blank");
|
|
295
|
-
},
|
|
296
|
-
},
|
|
297
|
-
"🔍 查看大图",
|
|
298
|
-
),
|
|
299
|
-
);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
var hint = React.createElement(
|
|
303
|
-
"div",
|
|
304
|
-
{ className: "std-hint" },
|
|
305
|
-
"💡 怎么用:在对话里告诉我设计需求(APP / Web / 软件界面均可)→ 生成后这里实时预览。不满意就在对话里说哪里要改(如「颜色换浅一点、品类改成四个」)→ 我改完点刷新看新版。每个设计都自带 1:1 HTML 源码,点上方「导出 1:1 HTML 源码」即可获取。",
|
|
306
|
-
);
|
|
307
|
-
|
|
308
|
-
body = React.createElement(React.Fragment, null, projectPicker, meta, preview, thumbs, actions, hint);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
return React.createElement(
|
|
313
|
-
"div",
|
|
314
|
-
{ className: "std-root" },
|
|
315
|
-
trigger,
|
|
316
|
-
opened
|
|
317
|
-
? React.createElement(
|
|
318
|
-
"div",
|
|
319
|
-
{ className: "std-panel", role: "dialog", "aria-label": "AI 设计预览" },
|
|
320
|
-
React.createElement(
|
|
321
|
-
"div",
|
|
322
|
-
{ className: "std-head" },
|
|
323
|
-
React.createElement("span", null, "AI 设计 · Stitch 预览"),
|
|
324
|
-
React.createElement(
|
|
325
|
-
"span",
|
|
326
|
-
{ className: "std-head-actions" },
|
|
327
|
-
React.createElement(
|
|
328
|
-
"button",
|
|
329
|
-
{
|
|
330
|
-
className: "std-btn",
|
|
331
|
-
disabled: loading,
|
|
332
|
-
onClick: function () {
|
|
333
|
-
refresh(selectedId || (data && data.projectId));
|
|
334
|
-
},
|
|
335
|
-
},
|
|
336
|
-
loading ? "刷新中…" : "刷新",
|
|
337
|
-
),
|
|
338
|
-
React.createElement(
|
|
339
|
-
"button",
|
|
340
|
-
{ className: "std-btn", onClick: function () { setOpened(false); } },
|
|
341
|
-
"关闭",
|
|
342
|
-
),
|
|
343
|
-
),
|
|
344
|
-
),
|
|
345
|
-
React.createElement("div", { className: "std-body" }, body),
|
|
346
|
-
)
|
|
347
|
-
: null,
|
|
348
|
-
);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
//#endregion
|
|
352
|
-
|
|
353
|
-
//#region API key card
|
|
354
|
-
|
|
355
44
|
/**
|
|
356
45
|
* The Stitch API-key card on the plugin's Plugins-page row.
|
|
357
46
|
*
|
|
@@ -447,64 +136,59 @@ window.__ModuleLoader__.load({
|
|
|
447
136
|
|
|
448
137
|
var configured = status && status.configured === true;
|
|
449
138
|
var statusLine = configured
|
|
450
|
-
? React.createElement(
|
|
451
|
-
: React.createElement(
|
|
139
|
+
? React.createElement(UI.Banner, { kind: "ok" }, "已配置(值不回读)。来源: " + (status.source || "file"))
|
|
140
|
+
: React.createElement(UI.Banner, { kind: "error" }, "未配置。设置后 15 个 mcp__stitch__* 工具即可用。");
|
|
452
141
|
|
|
453
142
|
return React.createElement(
|
|
454
|
-
|
|
455
|
-
{
|
|
456
|
-
|
|
143
|
+
UI.SettingsCard,
|
|
144
|
+
{
|
|
145
|
+
title: "Stitch API Key",
|
|
146
|
+
},
|
|
457
147
|
statusLine,
|
|
458
148
|
React.createElement(
|
|
459
149
|
"div",
|
|
460
|
-
{
|
|
461
|
-
React.createElement("input", {
|
|
462
|
-
className: "std-input",
|
|
463
|
-
type: "password",
|
|
464
|
-
value: value,
|
|
465
|
-
placeholder: configured ? "已设置(留空则不改)" : "粘贴 AQ. 开头的 key",
|
|
466
|
-
autoComplete: "off",
|
|
467
|
-
disabled: pending,
|
|
468
|
-
onChange: function (e) {
|
|
469
|
-
setValue(e.target.value);
|
|
470
|
-
},
|
|
471
|
-
}),
|
|
150
|
+
{ style: { display: "flex", alignItems: "center", gap: "8px" } },
|
|
472
151
|
React.createElement(
|
|
473
|
-
"
|
|
474
|
-
{
|
|
152
|
+
"div",
|
|
153
|
+
{ style: { flex: 1, minWidth: 0 } },
|
|
154
|
+
React.createElement(UI.TextField, {
|
|
155
|
+
type: "password",
|
|
156
|
+
value: value,
|
|
157
|
+
placeholder: configured ? "已设置(留空则不改)" : "粘贴 AQ. 开头的 key",
|
|
158
|
+
autoComplete: "off",
|
|
159
|
+
disabled: pending,
|
|
160
|
+
onValueChange: function (next) {
|
|
161
|
+
setValue(next);
|
|
162
|
+
},
|
|
163
|
+
}),
|
|
164
|
+
),
|
|
165
|
+
React.createElement(
|
|
166
|
+
UI.Button,
|
|
167
|
+
{ variant: "primary", disabled: pending || value === "", onClick: save },
|
|
475
168
|
pending ? "保存中…" : "保存",
|
|
476
169
|
),
|
|
477
170
|
React.createElement(
|
|
478
|
-
|
|
479
|
-
{
|
|
171
|
+
UI.Button,
|
|
172
|
+
{ variant: "secondary", disabled: pending || !configured, onClick: clear },
|
|
480
173
|
"清除",
|
|
481
174
|
),
|
|
482
175
|
),
|
|
483
176
|
React.createElement(
|
|
484
|
-
|
|
485
|
-
{
|
|
177
|
+
UI.Banner,
|
|
178
|
+
{ kind: "info" },
|
|
486
179
|
"key 来自 https://stitch.withgoogle.com(头像 → Stitch Settings → API key)。存于 $DSH_HOME/.credentials.yaml 的 STITCH_API_KEY,不写入插件配置行,因此不会以明文出现在 cordis.patch.yml。",
|
|
487
180
|
),
|
|
488
|
-
message
|
|
181
|
+
message
|
|
182
|
+
? React.createElement(
|
|
183
|
+
UI.Banner,
|
|
184
|
+
{ kind: message.indexOf("失败") >= 0 ? "error" : "info" },
|
|
185
|
+
message,
|
|
186
|
+
)
|
|
187
|
+
: null,
|
|
489
188
|
);
|
|
490
189
|
}
|
|
491
190
|
|
|
492
|
-
//#endregion
|
|
493
|
-
|
|
494
191
|
function apply(ctx) {
|
|
495
|
-
ctx.effect(function () {
|
|
496
|
-
return ctx.slots.inject("conversation.session.header.actions", function () {
|
|
497
|
-
return ctx.slots.register(
|
|
498
|
-
{
|
|
499
|
-
name: "conversation.session.header.actions",
|
|
500
|
-
id: "stitch-designer",
|
|
501
|
-
order: 40,
|
|
502
|
-
},
|
|
503
|
-
DesignerPanel,
|
|
504
|
-
);
|
|
505
|
-
});
|
|
506
|
-
}, "stitch-designer: preview panel");
|
|
507
|
-
|
|
508
192
|
// Nested: a host without a credential provider loses only this card.
|
|
509
193
|
ctx.inject(["remote.credentials"], function (scoped) {
|
|
510
194
|
BUNDLE_NAMES.forEach(function (bundle) {
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one design convention that is enforced rather than announced.
|
|
3
|
+
*
|
|
4
|
+
* "One code project owns exactly one Stitch project" is the only one of the
|
|
5
|
+
* three with a computable predicate, so it is the only one implemented here.
|
|
6
|
+
* The other two (TailwindCSS; implement from the exported HTML and ask before
|
|
7
|
+
* deviating) are prose, and live in `src/guidance.js` as the plugin's
|
|
8
|
+
* system-prompt announcement — a validator for them would be a lie.
|
|
9
|
+
*
|
|
10
|
+
* The rule is enforced rather than stated because a convention the model can
|
|
11
|
+
* silently break is not a convention. The id is recorded in the code project's
|
|
12
|
+
* own `.stitch.json`, and a second `create_project` from an already-bound
|
|
13
|
+
* directory is refused with the existing id — a refusal the model does not
|
|
14
|
+
* control. A recorded project that no longer exists upstream is cleared rather
|
|
15
|
+
* than obeyed, so the refusal can never become a permanent dead end.
|
|
16
|
+
*
|
|
17
|
+
* @module @logictan/dsh-stitch-designer/conventions
|
|
18
|
+
*/
|
|
19
|
+
import { clearBinding, readBinding, writeBinding } from './project.js';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Resolve the code project a tool call is running on behalf of.
|
|
23
|
+
*
|
|
24
|
+
* The session's working directory is the code project's identity here. A call
|
|
25
|
+
* with no agent (a probe, a nested dispatch) has no directory, so it gets no
|
|
26
|
+
* enforcement — that is not an error, it just has no project to bind.
|
|
27
|
+
*
|
|
28
|
+
* @param exec - the tool execution context.
|
|
29
|
+
* @returns the absolute directory, or `undefined`.
|
|
30
|
+
*/
|
|
31
|
+
function codeDirectory(exec) {
|
|
32
|
+
const cwd = exec?.agent?.session?.header?.cwd;
|
|
33
|
+
return typeof cwd === 'string' && cwd !== '' ? cwd : undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The Stitch project id inside a `projects/<id>` resource name.
|
|
38
|
+
*
|
|
39
|
+
* Stitch is inconsistent about this: `create_project`'s result carries the full
|
|
40
|
+
* resource name, while other payloads carry the bare id. Both shapes are
|
|
41
|
+
* accepted here rather than at each call site.
|
|
42
|
+
*
|
|
43
|
+
* @param value - a resource name, a bare id, or anything else.
|
|
44
|
+
* @returns the bare id, or `undefined`.
|
|
45
|
+
*/
|
|
46
|
+
function projectIdOf(value) {
|
|
47
|
+
const text = String(value ?? '');
|
|
48
|
+
if (text === '') return undefined;
|
|
49
|
+
return text.startsWith('projects/') ? text.split('/').pop() : text;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Whether a recorded project still exists upstream.
|
|
54
|
+
*
|
|
55
|
+
* Measured against the live server: an unknown or deleted project is answered
|
|
56
|
+
* with `content: [{ text: 'Requested entity was not found.' }]` and NO
|
|
57
|
+
* `structuredContent` — it is not an error response. That absence is the whole
|
|
58
|
+
* liveness signal.
|
|
59
|
+
*
|
|
60
|
+
* @param stitch - the Stitch client.
|
|
61
|
+
* @param projectId - the recorded project id.
|
|
62
|
+
* @returns whether the project is still there.
|
|
63
|
+
*/
|
|
64
|
+
async function projectExists(stitch, projectId) {
|
|
65
|
+
const result = await stitch.callTool('get_project', { name: `projects/${projectId}` }, undefined);
|
|
66
|
+
return result?.structuredContent?.name !== undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Build the wrapper that keeps one code project on one Stitch project.
|
|
71
|
+
*
|
|
72
|
+
* The wrapper is the seam that sees the code project a call belongs to, which
|
|
73
|
+
* is what makes the refusal possible at all — the Stitch tools themselves have
|
|
74
|
+
* no idea which repository is calling them.
|
|
75
|
+
*
|
|
76
|
+
* @param options - the Stitch client.
|
|
77
|
+
* @returns the `(rawName, args, exec)` invoker the tool definitions use.
|
|
78
|
+
*/
|
|
79
|
+
export function createInvoker(options) {
|
|
80
|
+
const { stitch } = options;
|
|
81
|
+
|
|
82
|
+
return async function invoke(rawName, args, exec) {
|
|
83
|
+
const directory = codeDirectory(exec);
|
|
84
|
+
const recorded = directory === undefined ? undefined : await readBinding(directory);
|
|
85
|
+
|
|
86
|
+
if (rawName === 'create_project' && directory !== undefined && recorded !== undefined) {
|
|
87
|
+
// A record pointing at a project that is gone must not be a dead end.
|
|
88
|
+
if (await projectExists(stitch, recorded.projectId)) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`This code project is already bound to Stitch project ${recorded.projectId} ` +
|
|
91
|
+
`(projects/${recorded.projectId}), recorded in ${directory}/.stitch.json. ` +
|
|
92
|
+
'One code project owns exactly one Stitch project, so no second one may be created for it. ' +
|
|
93
|
+
'Continue the existing project instead — list its screens, or generate into it with that projectId.',
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
await clearBinding(directory);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const result = await stitch.callTool(rawName, args, exec);
|
|
100
|
+
|
|
101
|
+
if (rawName === 'create_project') {
|
|
102
|
+
const created = projectIdOf(result?.structuredContent?.name);
|
|
103
|
+
if (created !== undefined && directory !== undefined) {
|
|
104
|
+
await writeBinding(directory, created);
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (rawName === 'delete_project') {
|
|
110
|
+
// The record is cleared only when it points at the project being deleted.
|
|
111
|
+
if (recorded !== undefined && projectIdOf(args?.name) === recorded.projectId) await clearBinding(directory);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return result;
|
|
115
|
+
};
|
|
116
|
+
}
|