@logictan/dsh-stitch-designer 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +91 -2
- package/cordis.patch.yml +22 -0
- package/lib/client.js +533 -0
- package/lib/index.js +153 -0
- package/lib/routes.js +250 -0
- package/lib/stitch.js +113 -0
- package/lib/store.js +229 -0
- package/lib/tools.js +165 -0
- package/package.json +71 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Logic Tan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,92 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @logictan/dsh-stitch-designer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Google Stitch (AI UI generation) inside DSH: the 15 `mcp__stitch__*` tools, plus
|
|
4
|
+
an in-session preview panel that shows each generated design, keeps a local
|
|
5
|
+
screenshot/HTML cache, and exports the 1:1 HTML source.
|
|
6
|
+
|
|
7
|
+
Ported from [liuxinlongwa-hue/dsh-stitch-designer](https://github.com/liuxinlongwa-hue/dsh-stitch-designer)
|
|
8
|
+
(MIT, © 2026 liuxinlongwa-hue): the preview panel, the screenshot cache, the
|
|
9
|
+
`state.json` persistence and the 1:1 HTML export come from that project. What
|
|
10
|
+
changed here is the tool surface and the key storage — see below.
|
|
11
|
+
|
|
12
|
+
## What it gives the model
|
|
13
|
+
|
|
14
|
+
The same 15 tools the `mcp-stitch` MCP row used to expose, under the same
|
|
15
|
+
public names, so existing prompts and habits keep working:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
mcp__stitch__create_project mcp__stitch__get_project
|
|
19
|
+
mcp__stitch__delete_project mcp__stitch__list_projects
|
|
20
|
+
mcp__stitch__list_screens mcp__stitch__get_screen
|
|
21
|
+
mcp__stitch__generate_screen_from_text mcp__stitch__edit_screens
|
|
22
|
+
mcp__stitch__generate_variants mcp__stitch__upload_design_md
|
|
23
|
+
mcp__stitch__create_design_system mcp__stitch__list_design_systems
|
|
24
|
+
mcp__stitch__create_design_system_from_design_md
|
|
25
|
+
mcp__stitch__update_design_system mcp__stitch__apply_design_system
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The tool list is read from Stitch at activation, not copied into this package,
|
|
29
|
+
so a tool Stitch adds or renames shows up without a code change. A call budget
|
|
30
|
+
of 180s covers `generate_screen_from_text`, which is long-running.
|
|
31
|
+
|
|
32
|
+
## Settings
|
|
33
|
+
|
|
34
|
+
`Settings → Plugins → stitch-designer`:
|
|
35
|
+
|
|
36
|
+
| Field | Meaning |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| Stitch API Key | The `STITCH_API_KEY` credential; write-only in the UI and never read back |
|
|
39
|
+
|
|
40
|
+
Get the key from <https://stitch.withgoogle.com> (avatar → Stitch Settings → API
|
|
41
|
+
key). It is stored in `$DSH_HOME/.credentials.yaml` as `STITCH_API_KEY` — **not**
|
|
42
|
+
in a plugin config row, so it never appears in plaintext in
|
|
43
|
+
`cordis.patch.yml`. Config sync carries it in its credentials section.
|
|
44
|
+
|
|
45
|
+
Setting the key registers the tools immediately; no restart is needed.
|
|
46
|
+
|
|
47
|
+
## The preview panel
|
|
48
|
+
|
|
49
|
+
The **AI 设计** button in the session header opens a panel showing the newest
|
|
50
|
+
design for the current project: a project picker, the full-size screenshot, a
|
|
51
|
+
thumbnail strip, and **导出 1:1 HTML 源码**.
|
|
52
|
+
|
|
53
|
+
Generation is driven from the conversation — ask for a design, and the model
|
|
54
|
+
calls `generate_screen_from_text`; ask for a change, and it calls
|
|
55
|
+
`edit_screens`. Then press **刷新** in the panel.
|
|
56
|
+
|
|
57
|
+
The panel exists because Stitch's `list_screens` index lags a generation by up
|
|
58
|
+
to a couple of minutes. This plugin reads the finished screen out of the
|
|
59
|
+
generation result, caches the screenshot and HTML under `~/.stitch`, and
|
|
60
|
+
remembers screen ids per project in `~/.stitch/state.json`, so a design appears
|
|
61
|
+
as soon as it exists instead of after the index catches up.
|
|
62
|
+
|
|
63
|
+
## HTTP routes
|
|
64
|
+
|
|
65
|
+
Served on the DSH web server, for the panel:
|
|
66
|
+
|
|
67
|
+
| Method | Path | Purpose |
|
|
68
|
+
| --- | --- | --- |
|
|
69
|
+
| GET | `/stitch/api/state` | Projects, screens and the cached preview for the current (or `?projectId=`) project |
|
|
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 |
|
|
73
|
+
|
|
74
|
+
## Local files
|
|
75
|
+
|
|
76
|
+
| Path | Contents |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| `$DSH_HOME/.credentials.yaml` | The API key, under `STITCH_API_KEY` |
|
|
79
|
+
| `~/.stitch/state.json` | Last used project and the remembered screen ids per project |
|
|
80
|
+
| `~/.stitch/screens/` | Cached screenshots |
|
|
81
|
+
| `~/.stitch/html/` | Exported 1:1 HTML sources |
|
|
82
|
+
|
|
83
|
+
## Replacing the `mcp-stitch` row
|
|
84
|
+
|
|
85
|
+
This plugin registers the 15 `mcp__stitch__*` names itself, so it **replaces**
|
|
86
|
+
the `mcp-stitch` MCP row rather than coexisting with it: two registrations of one
|
|
87
|
+
tool name throw. Remove that row from `$DSH_HOME/cordis.patch.yml` before
|
|
88
|
+
installing, and set the key on the Plugins page.
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT. See [LICENSE](./LICENSE).
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Patch row of @logictan/dsh-stitch-designer.
|
|
2
|
+
#
|
|
3
|
+
# Two rules this file must keep, both enforced elsewhere:
|
|
4
|
+
#
|
|
5
|
+
# - `name` is the BARE package name. A subpath (`@logictan/dsh-stitch-designer/client`)
|
|
6
|
+
# resolves to no manifest, so the loader cannot read `dsh.bundle.patch` and the row
|
|
7
|
+
# never mounts. The browser half is reached through the package's `./client` export,
|
|
8
|
+
# which `dsh-client-modules` reads from the manifest — never from this row.
|
|
9
|
+
# - `id` equals the host half's `export const name` ('stitch-designer' in
|
|
10
|
+
# src/index.js). `node scripts/aggregate.mjs --check` does NOT validate row-id
|
|
11
|
+
# uniqueness; `pnpm run check:host` does, and a duplicate hard-crashes the host
|
|
12
|
+
# with `duplicate loader entry id`. The "equals `export const name`" half has no
|
|
13
|
+
# automated check at all and is verified by hand.
|
|
14
|
+
#
|
|
15
|
+
# The row carries no `config:` — this plugin has no configuration of its own. The
|
|
16
|
+
# Stitch API key is NOT a patch value: it lives in the credentials file
|
|
17
|
+
# (`$DSH_HOME/.credentials.yaml`, ref `STITCH_API_KEY`) and is edited from the
|
|
18
|
+
# Plugins page, which is what makes it survive config sync without ever appearing
|
|
19
|
+
# in a plaintext snapshot as a patch row.
|
|
20
|
+
- insert:
|
|
21
|
+
- id: stitch-designer
|
|
22
|
+
name: '@logictan/dsh-stitch-designer'
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser half: the in-session Stitch preview panel and the API-key card.
|
|
3
|
+
*
|
|
4
|
+
* This file is already in the client module loader's protocol — it is not a
|
|
5
|
+
* module and imports nothing. `build.mjs` copies it to `lib/client.js`
|
|
6
|
+
* verbatim, which is why `package.json` exports `./client` at that path.
|
|
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
|
+
* `remote.credentials` is injected NESTED inside the card registration rather
|
|
15
|
+
* 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, and both surfaces
|
|
17
|
+
* live in one bundle — so a missing credential provider would take the panel
|
|
18
|
+
* down with the card. Nested, it costs only the card.
|
|
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.
|
|
23
|
+
*/
|
|
24
|
+
window.__ModuleLoader__.load({
|
|
25
|
+
id: "@logictan/dsh-stitch-designer",
|
|
26
|
+
factory: function (require) {
|
|
27
|
+
var React = require("react");
|
|
28
|
+
|
|
29
|
+
/** Loader entry id this card's row is keyed by; equals the host half's `export const name`. */
|
|
30
|
+
var ROW_ID = "stitch-designer";
|
|
31
|
+
/**
|
|
32
|
+
* Bundle package names whose row `ROW_ID` this card configures.
|
|
33
|
+
*
|
|
34
|
+
* The Plugins page keys a row's configuration by the package that declares
|
|
35
|
+
* the row, and this plugin reaches a profile in one of two shapes — as a
|
|
36
|
+
* dependency of this repository's aggregate bundle, or installed on its
|
|
37
|
+
* own. Both keys are registered; the one whose bundle is not installed
|
|
38
|
+
* never renders, because the page dispatches only the keys its own bundles
|
|
39
|
+
* declare.
|
|
40
|
+
*/
|
|
41
|
+
var BUNDLE_NAMES = ["@logictan/dsh-plugins-all", "@logictan/dsh-stitch-designer"];
|
|
42
|
+
/**
|
|
43
|
+
* Credential reference holding the Stitch API key.
|
|
44
|
+
*
|
|
45
|
+
* The key is NOT a plugin config field: `role('secret')` config values are
|
|
46
|
+
* written into the profile's `cordis.patch.yml` in plaintext, which is how
|
|
47
|
+
* the previous generation leaked keys into config-sync snapshots. A
|
|
48
|
+
* credential lives in `$DSH_HOME/.credentials.yaml` and is carried by the
|
|
49
|
+
* `credentialsStatus` sync section instead.
|
|
50
|
+
*/
|
|
51
|
+
var API_KEY_REF = "STITCH_API_KEY";
|
|
52
|
+
|
|
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
|
+
/**
|
|
356
|
+
* The Stitch API-key card on the plugin's Plugins-page row.
|
|
357
|
+
*
|
|
358
|
+
* The key is write-only across the wire: `describe` reports whether a value
|
|
359
|
+
* exists and never returns it, so the input is never pre-filled. That is a
|
|
360
|
+
* property of the credential seam, not a UI choice — and it is why this
|
|
361
|
+
* card needs no `configForms`: the only setting this plugin has is a
|
|
362
|
+
* credential, which the credential API already owns.
|
|
363
|
+
*/
|
|
364
|
+
function StitchKeyCard(props) {
|
|
365
|
+
var ctx = props.ctx;
|
|
366
|
+
var st = React.useState(null);
|
|
367
|
+
var status = st[0];
|
|
368
|
+
var setStatus = st[1];
|
|
369
|
+
var val = React.useState("");
|
|
370
|
+
var value = val[0];
|
|
371
|
+
var setValue = val[1];
|
|
372
|
+
var msg = React.useState("");
|
|
373
|
+
var message = msg[0];
|
|
374
|
+
var setMessage = msg[1];
|
|
375
|
+
var busy = React.useState(false);
|
|
376
|
+
var pending = busy[0];
|
|
377
|
+
var setPending = busy[1];
|
|
378
|
+
|
|
379
|
+
function read() {
|
|
380
|
+
return ctx.remote.credentials
|
|
381
|
+
.describe([API_KEY_REF])
|
|
382
|
+
.then(function (response) {
|
|
383
|
+
if (!response.ok) {
|
|
384
|
+
setMessage("读取失败: " + ((response.error && response.error.message) || "未知错误"));
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
setStatus(response.value[API_KEY_REF] || null);
|
|
388
|
+
})
|
|
389
|
+
.catch(function (e) {
|
|
390
|
+
setMessage("读取失败: " + ((e && e.message) || e));
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
React.useEffect(function () {
|
|
395
|
+
read();
|
|
396
|
+
var off = ctx.remote.$on("credentials/reference-updated", function (ref) {
|
|
397
|
+
if (ref === API_KEY_REF) read();
|
|
398
|
+
});
|
|
399
|
+
return function () {
|
|
400
|
+
if (typeof off === "function") off();
|
|
401
|
+
};
|
|
402
|
+
}, []);
|
|
403
|
+
|
|
404
|
+
function save() {
|
|
405
|
+
if (value === "") return;
|
|
406
|
+
setPending(true);
|
|
407
|
+
setMessage("");
|
|
408
|
+
ctx.remote.credentials
|
|
409
|
+
.set(API_KEY_REF, value)
|
|
410
|
+
.then(function (response) {
|
|
411
|
+
if (response && response.ok === false) {
|
|
412
|
+
setMessage("保存失败: " + ((response.error && response.error.message) || "未知错误"));
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
setValue("");
|
|
416
|
+
setMessage("已保存。密钥只存本机,随配置同步走 credentials 分区。");
|
|
417
|
+
return read();
|
|
418
|
+
})
|
|
419
|
+
.catch(function (e) {
|
|
420
|
+
setMessage("保存失败: " + ((e && e.message) || e));
|
|
421
|
+
})
|
|
422
|
+
.then(function () {
|
|
423
|
+
setPending(false);
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function clear() {
|
|
428
|
+
setPending(true);
|
|
429
|
+
setMessage("");
|
|
430
|
+
ctx.remote.credentials
|
|
431
|
+
.unset(API_KEY_REF)
|
|
432
|
+
.then(function (response) {
|
|
433
|
+
if (response && response.ok === false) {
|
|
434
|
+
setMessage("清除失败: " + ((response.error && response.error.message) || "未知错误"));
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
setMessage("已清除。");
|
|
438
|
+
return read();
|
|
439
|
+
})
|
|
440
|
+
.catch(function (e) {
|
|
441
|
+
setMessage("清除失败: " + ((e && e.message) || e));
|
|
442
|
+
})
|
|
443
|
+
.then(function () {
|
|
444
|
+
setPending(false);
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
var configured = status && status.configured === true;
|
|
449
|
+
var statusLine = configured
|
|
450
|
+
? React.createElement("div", { className: "std-note std-ok" }, "已配置(值不回读)。来源: " + (status.source || "file"))
|
|
451
|
+
: React.createElement("div", { className: "std-note std-bad" }, "未配置。设置后 15 个 mcp__stitch__* 工具即可用。");
|
|
452
|
+
|
|
453
|
+
return React.createElement(
|
|
454
|
+
"div",
|
|
455
|
+
{ className: "std-card" },
|
|
456
|
+
React.createElement("div", { className: "std-note" }, "Stitch API Key"),
|
|
457
|
+
statusLine,
|
|
458
|
+
React.createElement(
|
|
459
|
+
"div",
|
|
460
|
+
{ className: "std-card-row" },
|
|
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
|
+
}),
|
|
472
|
+
React.createElement(
|
|
473
|
+
"button",
|
|
474
|
+
{ className: "std-btn", disabled: pending || value === "", onClick: save },
|
|
475
|
+
pending ? "保存中…" : "保存",
|
|
476
|
+
),
|
|
477
|
+
React.createElement(
|
|
478
|
+
"button",
|
|
479
|
+
{ className: "std-btn", disabled: pending || !configured, onClick: clear },
|
|
480
|
+
"清除",
|
|
481
|
+
),
|
|
482
|
+
),
|
|
483
|
+
React.createElement(
|
|
484
|
+
"div",
|
|
485
|
+
{ className: "std-note" },
|
|
486
|
+
"key 来自 https://stitch.withgoogle.com(头像 → Stitch Settings → API key)。存于 $DSH_HOME/.credentials.yaml 的 STITCH_API_KEY,不写入插件配置行,因此不会以明文出现在 cordis.patch.yml。",
|
|
487
|
+
),
|
|
488
|
+
message ? React.createElement("div", { className: "std-note" }, message) : null,
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
//#endregion
|
|
493
|
+
|
|
494
|
+
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
|
+
// Nested: a host without a credential provider loses only this card.
|
|
509
|
+
ctx.inject(["remote.credentials"], function (scoped) {
|
|
510
|
+
BUNDLE_NAMES.forEach(function (bundle) {
|
|
511
|
+
scoped.slots.inject("plugins.row.config", function () {
|
|
512
|
+
return scoped.slots.register(
|
|
513
|
+
{
|
|
514
|
+
name: "plugins.row.config",
|
|
515
|
+
key: bundle + "#" + ROW_ID,
|
|
516
|
+
inject: function () {
|
|
517
|
+
return { ctx: scoped };
|
|
518
|
+
},
|
|
519
|
+
},
|
|
520
|
+
StitchKeyCard,
|
|
521
|
+
);
|
|
522
|
+
});
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
return {
|
|
528
|
+
name: "dsh-stitch-designer",
|
|
529
|
+
inject: ["slots", "remote"],
|
|
530
|
+
apply: apply,
|
|
531
|
+
};
|
|
532
|
+
},
|
|
533
|
+
});
|