-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathPromptsTab.tsx
More file actions
302 lines (278 loc) · 9.81 KB
/
Copy pathPromptsTab.tsx
File metadata and controls
302 lines (278 loc) · 9.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
import { useState } from "react";
import { ArrowLeft, Info, Plus, RotateCcw, Save, SquareSlash, Trash2, X } from "lucide-react";
import type { PromptArg, PromptDef, WebviewMessage } from "@perplexity-user-mcp/shared";
type SendFn = (m: WebviewMessage | Omit<Extract<WebviewMessage, { id: string }>, "id">) => void;
/** Mirrors CUSTOM_NAME_RE in mcp-server/src/prompts-config.ts. */
const NAME_RE = /^[a-z][a-z0-9-]*$/;
function emptyPrompt(): PromptDef {
return { name: "", description: "", arguments: [], template: "", isBuiltin: false, isModified: false };
}
function ReconnectNotice() {
return (
<div className="prompts-notice" role="note">
<Info size={13} className="prompts-notice-icon" />
<div>
<span className="prompts-notice-strong">Reconnect required after changes. </span>
MCP clients cache prompts at connect-time. After saving:
<ul className="prompts-notice-list">
<li><b>Cursor / Devin Desktop (Windsurf)</b> — Reload Window</li>
<li><b>Claude Code</b> — restart the session or run <code className="code-pill">/mcp</code></li>
<li><b>Claude Desktop</b> — restart the app</li>
</ul>
<span className="prompts-notice-muted">The embedded daemon picks up changes on the next connection automatically.</span>
</div>
</div>
);
}
function ArgRow({
arg,
onChange,
onRemove,
}: {
arg: PromptArg;
onChange: (updated: PromptArg) => void;
onRemove: () => void;
}) {
return (
<div className="prompts-arg-row">
<input
className="setting-input prompts-arg-name"
value={arg.name}
onChange={(e) => onChange({ ...arg, name: e.target.value })}
placeholder="name"
aria-label="Argument name"
/>
<input
className="setting-input prompts-arg-desc"
value={arg.description}
onChange={(e) => onChange({ ...arg, description: e.target.value })}
placeholder="description"
aria-label="Argument description"
/>
<label className="prompts-arg-req">
<input
type="checkbox"
checked={arg.required}
onChange={(e) => onChange({ ...arg, required: e.target.checked })}
aria-label="Required"
/>
req
</label>
<button className="ghost-button btn-sm prompts-arg-remove" onClick={onRemove} aria-label="Remove argument">
<X size={12} />
</button>
</div>
);
}
function PromptEditor({
initial,
isNew,
send,
onBack,
}: {
initial: PromptDef;
isNew: boolean;
send: SendFn;
onBack: () => void;
}) {
const [name, setName] = useState(initial.name);
const [description, setDescription] = useState(initial.description);
const [args, setArgs] = useState<PromptArg[]>(initial.arguments);
const [template, setTemplate] = useState(initial.template);
const [dirty, setDirty] = useState(isNew);
const nameValid = initial.isBuiltin || NAME_RE.test(name);
const canSave = dirty && nameValid && template.trim().length > 0;
function markDirty() {
setDirty(true);
}
function handleSave() {
if (!canSave) return;
send({
type: "prompts:save",
payload: {
prompt: { name, description, arguments: args, template, isBuiltin: initial.isBuiltin, isModified: initial.isBuiltin },
},
});
onBack();
}
function handleDelete() {
send({ type: "prompts:delete", payload: { name: initial.name } });
onBack();
}
function handleReset() {
send({ type: "prompts:reset", payload: { name: initial.name } });
onBack();
}
return (
<div className="grid gap-3">
<div className="glass-panel section-panel grid gap-3">
<button className="prompts-back" onClick={onBack}>
<ArrowLeft size={12} /> Back to prompts
</button>
<ReconnectNotice />
<div className="prompts-editor-title">
<span className="font-mono">{isNew ? "New prompt" : `/${initial.name}`}</span>
{initial.isBuiltin ? <span className="chip chip-accent">built-in</span> : null}
{initial.isModified ? <span className="chip chip-warn">modified</span> : null}
</div>
<div>
<label className="prompts-label">Slash command name</label>
<input
className="setting-input font-mono"
value={name}
disabled={initial.isBuiltin}
onChange={(e) => {
setName(e.target.value);
markDirty();
}}
placeholder="my-prompt"
aria-label="Prompt name"
/>
{!nameValid && name.length > 0 ? (
<div className="prompts-error">Lowercase letters, digits, and hyphens only (must start with a letter).</div>
) : (
<div className="prompts-hint">
Appears as <code className="code-pill">/{name || "…"}</code> in MCP clients.
</div>
)}
</div>
<div>
<label className="prompts-label">Description</label>
<input
className="setting-input"
value={description}
onChange={(e) => {
setDescription(e.target.value);
markDirty();
}}
placeholder="What this prompt does"
aria-label="Prompt description"
/>
</div>
<div>
<div className="prompts-args-head">
<label className="prompts-label">Arguments</label>
<button
className="ghost-button btn-sm"
onClick={() => {
setArgs((a) => [...a, { name: "", description: "", required: false }]);
markDirty();
}}
>
<Plus size={11} /> Add
</button>
</div>
{args.length === 0 ? (
<div className="prompts-hint">No arguments — this prompt has no user-fillable slots.</div>
) : (
<div className="grid gap-1.5">
{args.map((arg, i) => (
<ArgRow
key={i}
arg={arg}
onChange={(u) => {
setArgs((a) => a.map((x, idx) => (idx === i ? u : x)));
markDirty();
}}
onRemove={() => {
setArgs((a) => a.filter((_, idx) => idx !== i));
markDirty();
}}
/>
))}
</div>
)}
<div className="prompts-hint">
Use <code className="code-pill">{"{argName}"}</code> in the template to insert argument values.
</div>
</div>
<div>
<label className="prompts-label">Template</label>
<textarea
className="setting-input prompts-template"
value={template}
onChange={(e) => {
setTemplate(e.target.value);
markDirty();
}}
rows={10}
spellCheck={false}
aria-label="Prompt template"
/>
</div>
<div className="prompts-actions">
<button className="primary-button" disabled={!canSave} onClick={handleSave}>
<Save size={12} /> Save
</button>
{initial.isBuiltin && initial.isModified ? (
<button className="ghost-button" onClick={handleReset}>
<RotateCcw size={12} /> Reset to default
</button>
) : null}
{!initial.isBuiltin && !isNew ? (
<button className="danger-button" onClick={handleDelete}>
<Trash2 size={12} /> Delete
</button>
) : null}
</div>
</div>
</div>
);
}
export function PromptsTab({ prompts, send }: { prompts: PromptDef[]; send: SendFn }) {
const [editing, setEditing] = useState<{ prompt: PromptDef; isNew: boolean } | null>(null);
if (editing) {
return (
<PromptEditor
initial={editing.prompt}
isNew={editing.isNew}
send={send}
onBack={() => setEditing(null)}
/>
);
}
return (
<div className="grid gap-3">
<div className="glass-panel section-panel grid gap-3">
<div className="section-header">
<div className="section-header-row">
<div className="section-header-copy">
<div className="eyebrow">MCP</div>
<div className="title">Prompts</div>
<div className="detail">
Reusable slash commands available in Claude, Cursor, and every other connected MCP client.
</div>
</div>
<div className="section-header-action">
<button className="ghost-button btn-sm" onClick={() => setEditing({ prompt: emptyPrompt(), isNew: true })}>
<Plus size={13} /> New prompt
</button>
</div>
</div>
</div>
<ReconnectNotice />
{prompts.length === 0 ? (
<div className="empty-state">No prompts yet. Create one with the New prompt button.</div>
) : (
<div className="grid gap-2">
{prompts.map((p) => (
<button key={p.name} className="action-card" onClick={() => setEditing({ prompt: p, isNew: false })}>
<div className="icon-badge">
<SquareSlash size={13} />
</div>
<div className="action-card-body">
<div className="action-card-title prompts-card-title">
<span className="font-mono">/{p.name}</span>
{p.isBuiltin ? <span className="chip chip-muted">built-in</span> : null}
{p.isModified ? <span className="chip chip-warn">modified</span> : null}
</div>
<div className="action-card-desc">{p.description}</div>
</div>
</button>
))}
</div>
)}
</div>
</div>
);
}