paseo-quick-prompts 0.0.0-stage → 0.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/LICENSE +21 -0
- package/OVERVIEW.md +20 -0
- package/README.md +93 -2
- package/client/follow.ts +53 -0
- package/client/pills.ts +179 -0
- package/client/settings-screen.tsx +369 -0
- package/index.client.tsx +30 -0
- package/index.server.ts +7 -0
- package/package.json +44 -4
- package/paseo-plugin.json +8 -0
- package/shared/prompts.ts +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kingsley
|
|
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/OVERVIEW.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Quick prompts turns the messages you send often into pills above every agent's composer. Tap a pill and its text goes to that agent as your next message, the same as typing it and pressing send. If you prefer a tidier composer, show them all in one **Prompts** pill that opens a menu instead.
|
|
2
|
+
|
|
3
|
+
Use it for prompts you repeat across agents, such as "Review the uncommitted changes", "Run the tests and fix failures", or "Summarize what changed and open a PR".
|
|
4
|
+
|
|
5
|
+
## Settings
|
|
6
|
+
|
|
7
|
+
Open **Settings → Plugins → paseo-quick-prompts → Quick prompts** to add, edit, reorder, and delete prompts and to choose how they appear. Each one has a label, shown on the pill or menu item, and the prompt text that is sent. Changes apply after you press **Save**; **Discard** returns to the saved settings.
|
|
8
|
+
|
|
9
|
+
- Up to 20 prompts. Labels can be up to 40 characters.
|
|
10
|
+
- **Show prompts as** picks **Separate pills** (the default) or **One menu pill**. Either way, prompts follow the order of the list, on every agent that belongs to a workspace. The menu also has a **Manage prompts** item that opens the settings page.
|
|
11
|
+
- With no prompts saved, each agent shows an **Add quick prompt** pill that opens the settings page.
|
|
12
|
+
|
|
13
|
+
The settings page also has a tip with a prompt you can copy and send to an agent, which reads your Paseo agent history and suggests the quick prompts you would use most.
|
|
14
|
+
|
|
15
|
+
Prompts are stored on the Paseo host and shared by every app connected to it.
|
|
16
|
+
|
|
17
|
+
## Limits
|
|
18
|
+
|
|
19
|
+
- A pill sends right away. It does not put the text in the composer for editing first.
|
|
20
|
+
- Pills appear on existing agents, not in the composer for a new agent.
|
package/README.md
CHANGED
|
@@ -1,3 +1,94 @@
|
|
|
1
|
-
#
|
|
1
|
+
# paseo-quick-prompts
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Saved prompts as one-tap pills above every agent's composer in [Paseo](https://github.com/getpaseo/paseo).**
|
|
4
|
+
|
|
5
|
+
Save the messages you send often, like "Review the uncommitted changes" or "Run the tests and fix
|
|
6
|
+
failures". Each one becomes a pill above every agent's composer; tapping it sends the prompt to that
|
|
7
|
+
agent as a normal user message.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **One pill per prompt** on every agent with a workspace, in the order you set, or **one menu
|
|
12
|
+
pill** (Prompts) that lists them all with a **Manage prompts** shortcut.
|
|
13
|
+
- **Settings screen** under **Settings → Plugins → paseo-quick-prompts → Quick prompts** to add, edit, reorder, and delete
|
|
14
|
+
prompts and choose how they appear, with explicit **Save** and **Discard**.
|
|
15
|
+
- **Prompt ideas.** A copyable prompt on the settings screen asks an agent to read your Paseo agent
|
|
16
|
+
history and suggest the quick prompts you would use most.
|
|
17
|
+
- **Shared per host.** Prompts are stored on the daemon and every connected app sees the same list;
|
|
18
|
+
pills update live when it changes.
|
|
19
|
+
- **Empty state.** With no prompts saved, each agent shows an **Add quick prompt** pill that opens
|
|
20
|
+
the settings screen.
|
|
21
|
+
|
|
22
|
+
## Requirements
|
|
23
|
+
|
|
24
|
+
- Paseo **0.11.0** or later, with plugins enabled (**Settings → Plugins → Enable plugins**, or
|
|
25
|
+
`"pluginsEnabled": true` in `~/.paseo/config.json`)
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
paseo plugin install npm:paseo-quick-prompts
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
You can also paste `npm:paseo-quick-prompts` into **Settings → Plugins → Plugin source**, or install
|
|
34
|
+
the latest source with `paseo plugin install github:kingsleydon/paseo-plugins:plugins/quick-prompts`.
|
|
35
|
+
|
|
36
|
+
## Settings
|
|
37
|
+
|
|
38
|
+
| Field | Limit | Description |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| Label | 1–40 characters | Text on the pill |
|
|
41
|
+
| Prompt | 1–10,000 characters | Message sent to the agent |
|
|
42
|
+
|
|
43
|
+
Up to 20 prompts. Leading and trailing whitespace is trimmed when you save.
|
|
44
|
+
|
|
45
|
+
**Show prompts as** is **Separate pills** (default) or **One menu pill**. Settings saved before this
|
|
46
|
+
option existed keep separate pills.
|
|
47
|
+
|
|
48
|
+
## How it works
|
|
49
|
+
|
|
50
|
+
- The settings document (`prompts`, host scope) is registered by the daemon entry and stored by Paseo.
|
|
51
|
+
- The app entry follows the agent directory with an owned list subscription and re-reads the prompts
|
|
52
|
+
whenever any client saves them, then keeps one composer pill per prompt (or one menu pill) on each
|
|
53
|
+
non-archived agent that has a workspace. Prompt changes update existing pills in place; a reorder
|
|
54
|
+
of separate pills or a display switch re-registers that agent's pills.
|
|
55
|
+
- A pill press or menu choice calls `paseo.agents.ref(agentId).send(text)`. Paseo shows the pill as busy until the
|
|
56
|
+
send settles and reports failures in a toast.
|
|
57
|
+
|
|
58
|
+
Not supported: pills in the new-agent composer, inserting text into the composer for editing, and
|
|
59
|
+
import or export.
|
|
60
|
+
|
|
61
|
+
## Development
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npm install
|
|
65
|
+
npm run typecheck
|
|
66
|
+
npm test
|
|
67
|
+
paseo plugin install "$PWD"
|
|
68
|
+
paseo plugin reload paseo-quick-prompts # after changes
|
|
69
|
+
paseo plugin logs paseo-quick-prompts
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
| Path | Contents |
|
|
73
|
+
|---|---|
|
|
74
|
+
| `index.server.ts` | Daemon entry: registers the settings document |
|
|
75
|
+
| `index.client.tsx` | App entry: settings screen and composer pills |
|
|
76
|
+
| `client/pills.ts` | Keeps each agent's pills in sync with the saved prompts |
|
|
77
|
+
| `client/follow.ts` | Follows the agent directory and settings changes |
|
|
78
|
+
| `client/settings-screen.tsx` | Draft editor for the prompts and display option, and the prompt-ideas tip |
|
|
79
|
+
| `shared/prompts.ts` | Settings schema and limits |
|
|
80
|
+
|
|
81
|
+
## Releasing
|
|
82
|
+
|
|
83
|
+
Bump `version` in `package.json` in a PR, merge it, then tag the merged commit with
|
|
84
|
+
`quick-prompts-v<version>`:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
git tag quick-prompts-v0.1.0 && git push origin quick-prompts-v0.1.0
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
See the [repository README](../../README.md#releasing) for how the publish workflow works.
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
[MIT](LICENSE)
|
package/client/follow.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { settingsRpc } from "@getpaseo/plugin";
|
|
2
|
+
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
3
|
+
import { quickPromptsSettings, settingsFromRead } from "../shared/prompts";
|
|
4
|
+
import type { PromptPills } from "./pills";
|
|
5
|
+
|
|
6
|
+
type Client = Pick<PluginClientContext, "paseo" | "rpc">;
|
|
7
|
+
|
|
8
|
+
/** Follows the agent directory: existing agents first, then updates, and a fresh snapshot after a reconnect. */
|
|
9
|
+
export function followAgents(client: Client, pills: PromptPills, signal: AbortSignal): void {
|
|
10
|
+
client.paseo.agents
|
|
11
|
+
.list({ subscribe: {}, signal })
|
|
12
|
+
.then(({ subscription }) => {
|
|
13
|
+
subscription.subscribe({
|
|
14
|
+
snapshot: ({ entries }) => pills.setAgents(entries.map(({ agent }) => agent)),
|
|
15
|
+
update: (message) => {
|
|
16
|
+
if (message.type !== "agent_update") return;
|
|
17
|
+
const update = message.payload;
|
|
18
|
+
if (update.kind === "remove") pills.removeAgent(update.agentId);
|
|
19
|
+
else pills.upsertAgent(update.agent);
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
})
|
|
23
|
+
.catch((error: unknown) => {
|
|
24
|
+
if (!signal.aborted) console.error("[paseo-quick-prompts] agent observation failed", error);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Reads the saved prompts now, after a reconnect, and whenever any client saves them. */
|
|
29
|
+
export function followPrompts(client: Client, pills: PromptPills, signal: AbortSignal): void {
|
|
30
|
+
const { read } = settingsRpc(quickPromptsSettings.id);
|
|
31
|
+
let latest = 0;
|
|
32
|
+
const load = async (): Promise<void> => {
|
|
33
|
+
const request = ++latest;
|
|
34
|
+
try {
|
|
35
|
+
const result = await client.rpc(read, {});
|
|
36
|
+
if (!signal.aborted && request === latest) pills.setSettings(settingsFromRead(result));
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (!signal.aborted) console.error("[paseo-quick-prompts] failed to load quick prompts", error);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
client.paseo.observeEvents(["status.plugin_settings_changed"], { signal }).subscribe({
|
|
42
|
+
snapshot: () => void load(),
|
|
43
|
+
update: (message) => {
|
|
44
|
+
if (
|
|
45
|
+
message.type === "status" &&
|
|
46
|
+
message.payload.status === "plugin_settings_changed" &&
|
|
47
|
+
message.payload.settingsId === quickPromptsSettings.id
|
|
48
|
+
) {
|
|
49
|
+
void load();
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
package/client/pills.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PluginButton,
|
|
3
|
+
PluginButtonRegistration,
|
|
4
|
+
PluginComposerPillContribution,
|
|
5
|
+
} from "@getpaseo/plugin/client";
|
|
6
|
+
import type { QuickPrompt, QuickPromptsSettings } from "../shared/prompts";
|
|
7
|
+
|
|
8
|
+
const ADD_PILL_ID = "add-quick-prompt";
|
|
9
|
+
const MENU_PILL_ID = "quick-prompts";
|
|
10
|
+
|
|
11
|
+
export interface PromptPillHost {
|
|
12
|
+
addComposerPill(contribution: PluginComposerPillContribution): PluginButtonRegistration;
|
|
13
|
+
send(agentId: string, text: string): Promise<void>;
|
|
14
|
+
openSettings(): void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface PillAgent {
|
|
18
|
+
id: string;
|
|
19
|
+
workspaceId?: string | null;
|
|
20
|
+
archivedAt?: string | null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface PromptPills {
|
|
24
|
+
setSettings(settings: QuickPromptsSettings): void;
|
|
25
|
+
/** Replaces the agent list with a full snapshot. */
|
|
26
|
+
setAgents(agents: readonly PillAgent[]): void;
|
|
27
|
+
upsertAgent(agent: PillAgent): void;
|
|
28
|
+
removeAgent(agentId: string): void;
|
|
29
|
+
removeAll(): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A pill an agent should show; `content` changes whenever its button does. */
|
|
33
|
+
interface PillSpec {
|
|
34
|
+
id: string;
|
|
35
|
+
content: string;
|
|
36
|
+
button(agentId: string): PluginButton;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface Pill {
|
|
40
|
+
id: string;
|
|
41
|
+
content: string;
|
|
42
|
+
registration: PluginButtonRegistration;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface AgentPills {
|
|
46
|
+
workspaceId: string;
|
|
47
|
+
pills: Pill[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Keeps one composer pill per saved prompt on every agent, a single "Prompts" pill whose menu
|
|
52
|
+
* lists them, or a single "Add quick prompt" pill when none are saved. Pills whose order is
|
|
53
|
+
* unchanged update in place; a reorder, addition, removal, or display switch re-registers that
|
|
54
|
+
* agent's pills, because registration order is display order.
|
|
55
|
+
*
|
|
56
|
+
* A factory rather than a class: plugin client bundles reach Hermes (iOS, Android) without Metro's
|
|
57
|
+
* transforms, and Hermes rejects class syntax (getpaseo/paseo#5783).
|
|
58
|
+
*/
|
|
59
|
+
export function createPromptPills(host: PromptPillHost): PromptPills {
|
|
60
|
+
/** Null until the first read, so agents do not flash the "Add quick prompt" pill. */
|
|
61
|
+
let specs: readonly PillSpec[] | null = null;
|
|
62
|
+
/** Agents that get pills, by id, with their workspace. */
|
|
63
|
+
const targets = new Map<string, string>();
|
|
64
|
+
const registered = new Map<string, AgentPills>();
|
|
65
|
+
|
|
66
|
+
const addSpec: PillSpec = {
|
|
67
|
+
id: ADD_PILL_ID,
|
|
68
|
+
content: "",
|
|
69
|
+
button: () => ({
|
|
70
|
+
title: "Add a quick prompt in settings",
|
|
71
|
+
icon: "Plus",
|
|
72
|
+
label: "Add quick prompt",
|
|
73
|
+
behavior: { kind: "action", onPress: () => host.openSettings() },
|
|
74
|
+
}),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const promptSpec = (prompt: QuickPrompt): PillSpec => ({
|
|
78
|
+
id: `prompt-${prompt.id}`,
|
|
79
|
+
content: JSON.stringify([prompt.label, prompt.text]),
|
|
80
|
+
button: (agentId) => ({
|
|
81
|
+
title: `Send quick prompt: ${prompt.label}`,
|
|
82
|
+
icon: "Zap",
|
|
83
|
+
label: prompt.label,
|
|
84
|
+
// Paseo marks the pill busy until the send settles and shows a failure in a toast.
|
|
85
|
+
behavior: { kind: "action", onPress: () => host.send(agentId, prompt.text) },
|
|
86
|
+
}),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const menuSpec = (prompts: readonly QuickPrompt[]): PillSpec => ({
|
|
90
|
+
id: MENU_PILL_ID,
|
|
91
|
+
content: JSON.stringify(prompts),
|
|
92
|
+
button: (agentId) => ({
|
|
93
|
+
title: "Send a quick prompt",
|
|
94
|
+
icon: "Zap",
|
|
95
|
+
label: "Prompts",
|
|
96
|
+
behavior: {
|
|
97
|
+
kind: "menu",
|
|
98
|
+
items: [
|
|
99
|
+
...prompts.map((prompt) => ({
|
|
100
|
+
kind: "item" as const,
|
|
101
|
+
id: `prompt-${prompt.id}`,
|
|
102
|
+
title: prompt.label,
|
|
103
|
+
behavior: { kind: "action" as const, onPress: () => host.send(agentId, prompt.text) },
|
|
104
|
+
})),
|
|
105
|
+
{ kind: "separator", id: "manage-divider" },
|
|
106
|
+
{
|
|
107
|
+
kind: "item",
|
|
108
|
+
id: "manage",
|
|
109
|
+
title: "Manage prompts",
|
|
110
|
+
icon: "Settings",
|
|
111
|
+
behavior: { kind: "action", onPress: () => host.openSettings() },
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const clear = (agentId: string): void => {
|
|
119
|
+
for (const pill of registered.get(agentId)?.pills ?? []) pill.registration.remove();
|
|
120
|
+
registered.delete(agentId);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const sync = (agentId: string, workspaceId: string): void => {
|
|
124
|
+
if (specs === null) return;
|
|
125
|
+
const next = specs;
|
|
126
|
+
const current = registered.get(agentId);
|
|
127
|
+
const sameOrder =
|
|
128
|
+
current?.workspaceId === workspaceId &&
|
|
129
|
+
current.pills.length === next.length &&
|
|
130
|
+
current.pills.every((pill, index) => pill.id === next[index]?.id);
|
|
131
|
+
if (current && sameOrder) {
|
|
132
|
+
current.pills.forEach((pill, index) => {
|
|
133
|
+
const spec = next[index];
|
|
134
|
+
if (!spec || pill.content === spec.content) return;
|
|
135
|
+
pill.content = spec.content;
|
|
136
|
+
// The full button, so a menu gets its complete new behavior.
|
|
137
|
+
pill.registration.update(spec.button(agentId));
|
|
138
|
+
});
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
clear(agentId);
|
|
142
|
+
registered.set(agentId, {
|
|
143
|
+
workspaceId,
|
|
144
|
+
pills: next.map(({ id, content, button }) => {
|
|
145
|
+
const registration = host.addComposerPill({ id, workspaceId, agentId, button: button(agentId) });
|
|
146
|
+
return { id, content, registration };
|
|
147
|
+
}),
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const removeAgent = (agentId: string): void => {
|
|
152
|
+
targets.delete(agentId);
|
|
153
|
+
clear(agentId);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const upsertAgent = (agent: PillAgent): void => {
|
|
157
|
+
if (!agent.workspaceId || agent.archivedAt) return removeAgent(agent.id);
|
|
158
|
+
targets.set(agent.id, agent.workspaceId);
|
|
159
|
+
sync(agent.id, agent.workspaceId);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
setSettings({ prompts, display }) {
|
|
164
|
+
if (prompts.length === 0) specs = [addSpec];
|
|
165
|
+
else specs = display === "menu" ? [menuSpec(prompts)] : prompts.map(promptSpec);
|
|
166
|
+
for (const [agentId, workspaceId] of targets) sync(agentId, workspaceId);
|
|
167
|
+
},
|
|
168
|
+
setAgents(list) {
|
|
169
|
+
const ids = new Set(list.map(({ id }) => id));
|
|
170
|
+
for (const agentId of [...targets.keys()]) if (!ids.has(agentId)) removeAgent(agentId);
|
|
171
|
+
for (const agent of list) upsertAgent(agent);
|
|
172
|
+
},
|
|
173
|
+
upsertAgent,
|
|
174
|
+
removeAgent,
|
|
175
|
+
removeAll() {
|
|
176
|
+
for (const agentId of [...targets.keys()]) removeAgent(agentId);
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import { useSettings, type PluginSurfaceProps, type SettingsState } from "@getpaseo/plugin/client";
|
|
2
|
+
import { copyText, useToast } from "@getpaseo/plugin/client/react-native";
|
|
3
|
+
import {
|
|
4
|
+
SettingsAction,
|
|
5
|
+
SettingsCard,
|
|
6
|
+
SettingsInput,
|
|
7
|
+
SettingsRow,
|
|
8
|
+
SettingsSection,
|
|
9
|
+
SettingsSelect,
|
|
10
|
+
} from "@getpaseo/plugin/client/ui";
|
|
11
|
+
import { useMemo, useState } from "react";
|
|
12
|
+
import { Pressable, Text, TextInput, View } from "react-native";
|
|
13
|
+
import {
|
|
14
|
+
LABEL_MAX_LENGTH,
|
|
15
|
+
MAX_PROMPTS,
|
|
16
|
+
newPromptId,
|
|
17
|
+
quickPromptsSettings,
|
|
18
|
+
TEXT_MAX_LENGTH,
|
|
19
|
+
type PromptDisplay,
|
|
20
|
+
type QuickPrompt,
|
|
21
|
+
type QuickPromptsSettings,
|
|
22
|
+
} from "../shared/prompts";
|
|
23
|
+
|
|
24
|
+
type ReadySettings = Extract<SettingsState<typeof quickPromptsSettings.schema>, { status: "ready" }>;
|
|
25
|
+
type Theme = PluginSurfaceProps["theme"];
|
|
26
|
+
type Field = "label" | "text";
|
|
27
|
+
|
|
28
|
+
/** Unsaved edits with the revision they started from, so a save over another client's change conflicts. */
|
|
29
|
+
interface Draft {
|
|
30
|
+
values: QuickPromptsSettings;
|
|
31
|
+
revision: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const DISPLAY_OPTIONS: ReadonlyArray<{ label: string; value: PromptDisplay }> = [
|
|
35
|
+
{ label: "Separate pills", value: "pills" },
|
|
36
|
+
{ label: "One menu pill", value: "menu" },
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
const FIND_PROMPTS_PROMPT =
|
|
40
|
+
"Look through my past Paseo agent sessions using the Paseo tools (list my agents and read their " +
|
|
41
|
+
"activity) and find the follow-up messages I send most often. Suggest the 5 most useful quick prompts " +
|
|
42
|
+
"for me. For each one give a short label (40 characters or fewer) and the full prompt text, written so " +
|
|
43
|
+
"it works for any task. Do not change anything; just list them so I can add them in Quick prompts.";
|
|
44
|
+
|
|
45
|
+
interface Validation {
|
|
46
|
+
valid: boolean;
|
|
47
|
+
fields: Array<Partial<Record<Field, string>>>;
|
|
48
|
+
list: string | null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function validate(values: QuickPromptsSettings): Validation {
|
|
52
|
+
const parsed = quickPromptsSettings.schema.safeParse(values);
|
|
53
|
+
const fields: Validation["fields"] = values.prompts.map(() => ({}));
|
|
54
|
+
let list: string | null = null;
|
|
55
|
+
for (const issue of parsed.error?.issues ?? []) {
|
|
56
|
+
const [, index, field] = issue.path;
|
|
57
|
+
if (typeof index === "number" && (field === "label" || field === "text")) {
|
|
58
|
+
fields[index] = { ...fields[index], [field]: fields[index]?.[field] ?? issue.message };
|
|
59
|
+
} else {
|
|
60
|
+
list ??= issue.message;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return { valid: parsed.success, fields, list };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function useStyles(theme: Theme, compact: boolean) {
|
|
67
|
+
return useMemo(
|
|
68
|
+
() => ({
|
|
69
|
+
intro: { color: theme.colors.foregroundMuted, fontSize: 13, lineHeight: 18 },
|
|
70
|
+
message: { color: theme.colors.foreground },
|
|
71
|
+
editor: { paddingHorizontal: compact ? 12 : 16, paddingVertical: compact ? 10 : 12 },
|
|
72
|
+
textInput: {
|
|
73
|
+
minHeight: 88,
|
|
74
|
+
padding: 10,
|
|
75
|
+
borderRadius: 8,
|
|
76
|
+
borderWidth: 1,
|
|
77
|
+
borderColor: theme.colors.border,
|
|
78
|
+
backgroundColor: theme.colors.surface2,
|
|
79
|
+
color: theme.colors.foreground,
|
|
80
|
+
fontSize: 14,
|
|
81
|
+
textAlignVertical: "top" as const,
|
|
82
|
+
},
|
|
83
|
+
buttons: { flexDirection: "row" as const, flexWrap: "wrap" as const, gap: 8 },
|
|
84
|
+
button: {
|
|
85
|
+
paddingHorizontal: 10,
|
|
86
|
+
paddingVertical: 6,
|
|
87
|
+
borderRadius: 6,
|
|
88
|
+
borderWidth: 1,
|
|
89
|
+
borderColor: theme.colors.border,
|
|
90
|
+
},
|
|
91
|
+
buttonDisabled: { opacity: 0.4 },
|
|
92
|
+
buttonText: { color: theme.colors.foreground, fontSize: 13 },
|
|
93
|
+
dangerText: { color: theme.colors.statusDanger, fontSize: 13 },
|
|
94
|
+
tipPrompt: { color: theme.colors.foreground, fontSize: 13, lineHeight: 18 },
|
|
95
|
+
}),
|
|
96
|
+
[theme, compact],
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
type Styles = ReturnType<typeof useStyles>;
|
|
101
|
+
|
|
102
|
+
function SmallButton({
|
|
103
|
+
label,
|
|
104
|
+
accessibilityLabel,
|
|
105
|
+
danger,
|
|
106
|
+
disabled,
|
|
107
|
+
styles,
|
|
108
|
+
onPress,
|
|
109
|
+
}: {
|
|
110
|
+
label: string;
|
|
111
|
+
accessibilityLabel: string;
|
|
112
|
+
danger?: boolean;
|
|
113
|
+
disabled?: boolean;
|
|
114
|
+
styles: Styles;
|
|
115
|
+
onPress(): void;
|
|
116
|
+
}) {
|
|
117
|
+
return (
|
|
118
|
+
<Pressable
|
|
119
|
+
accessibilityRole="button"
|
|
120
|
+
accessibilityLabel={accessibilityLabel}
|
|
121
|
+
accessibilityState={{ disabled: Boolean(disabled) }}
|
|
122
|
+
disabled={disabled}
|
|
123
|
+
onPress={onPress}
|
|
124
|
+
style={disabled ? [styles.button, styles.buttonDisabled] : styles.button}
|
|
125
|
+
>
|
|
126
|
+
<Text style={danger ? styles.dangerText : styles.buttonText}>{label}</Text>
|
|
127
|
+
</Pressable>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function PromptEditor({
|
|
132
|
+
prompt,
|
|
133
|
+
index,
|
|
134
|
+
count,
|
|
135
|
+
errors,
|
|
136
|
+
inputKey,
|
|
137
|
+
disabled,
|
|
138
|
+
theme,
|
|
139
|
+
styles,
|
|
140
|
+
onChange,
|
|
141
|
+
onMove,
|
|
142
|
+
onDelete,
|
|
143
|
+
}: {
|
|
144
|
+
prompt: QuickPrompt;
|
|
145
|
+
index: number;
|
|
146
|
+
count: number;
|
|
147
|
+
errors: Partial<Record<Field, string>>;
|
|
148
|
+
inputKey: string;
|
|
149
|
+
disabled: boolean;
|
|
150
|
+
theme: Theme;
|
|
151
|
+
styles: Styles;
|
|
152
|
+
onChange(field: Field, value: string): void;
|
|
153
|
+
onMove(offset: -1 | 1): void;
|
|
154
|
+
onDelete(): void;
|
|
155
|
+
}) {
|
|
156
|
+
const name = prompt.label.trim() || `quick prompt ${index + 1}`;
|
|
157
|
+
return (
|
|
158
|
+
<SettingsCard>
|
|
159
|
+
<SettingsInput
|
|
160
|
+
key={inputKey}
|
|
161
|
+
label="Label"
|
|
162
|
+
hint="Shown on the pill."
|
|
163
|
+
initialValue={prompt.label}
|
|
164
|
+
placeholder="Review changes"
|
|
165
|
+
error={errors.label}
|
|
166
|
+
disabled={disabled}
|
|
167
|
+
onChangeText={(text) => onChange("label", text)}
|
|
168
|
+
/>
|
|
169
|
+
<SettingsRow label="Prompt" hint="Sent to the agent as your message." error={errors.text} />
|
|
170
|
+
<View style={styles.editor}>
|
|
171
|
+
<TextInput
|
|
172
|
+
multiline
|
|
173
|
+
accessibilityLabel={`Prompt for ${name}`}
|
|
174
|
+
value={prompt.text}
|
|
175
|
+
editable={!disabled}
|
|
176
|
+
maxLength={TEXT_MAX_LENGTH}
|
|
177
|
+
placeholder="Review the uncommitted changes and list any bugs."
|
|
178
|
+
placeholderTextColor={theme.colors.foregroundMuted}
|
|
179
|
+
onChangeText={(text) => onChange("text", text)}
|
|
180
|
+
style={styles.textInput}
|
|
181
|
+
/>
|
|
182
|
+
</View>
|
|
183
|
+
<View style={[styles.editor, styles.buttons]}>
|
|
184
|
+
<SmallButton
|
|
185
|
+
label="Move up"
|
|
186
|
+
accessibilityLabel={`Move ${name} up`}
|
|
187
|
+
disabled={disabled || index === 0}
|
|
188
|
+
styles={styles}
|
|
189
|
+
onPress={() => onMove(-1)}
|
|
190
|
+
/>
|
|
191
|
+
<SmallButton
|
|
192
|
+
label="Move down"
|
|
193
|
+
accessibilityLabel={`Move ${name} down`}
|
|
194
|
+
disabled={disabled || index === count - 1}
|
|
195
|
+
styles={styles}
|
|
196
|
+
onPress={() => onMove(1)}
|
|
197
|
+
/>
|
|
198
|
+
<SmallButton
|
|
199
|
+
label="Delete"
|
|
200
|
+
accessibilityLabel={`Delete ${name}`}
|
|
201
|
+
danger
|
|
202
|
+
disabled={disabled}
|
|
203
|
+
styles={styles}
|
|
204
|
+
onPress={onDelete}
|
|
205
|
+
/>
|
|
206
|
+
</View>
|
|
207
|
+
</SettingsCard>
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function FindPromptsTip({ styles }: { styles: Styles }) {
|
|
212
|
+
const toast = useToast();
|
|
213
|
+
const copy = async (): Promise<void> => {
|
|
214
|
+
try {
|
|
215
|
+
await copyText(FIND_PROMPTS_PROMPT);
|
|
216
|
+
toast.show("Copied", { variant: "success" });
|
|
217
|
+
} catch {
|
|
218
|
+
toast.error("Could not copy. Select the text and use Copy.");
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
return (
|
|
222
|
+
<SettingsCard>
|
|
223
|
+
<SettingsAction
|
|
224
|
+
label="Not sure what to add?"
|
|
225
|
+
hint="Ask an agent to look through your past sessions and suggest your most useful quick prompts."
|
|
226
|
+
actionLabel="Copy prompt"
|
|
227
|
+
onPress={() => void copy()}
|
|
228
|
+
/>
|
|
229
|
+
<View style={styles.editor}>
|
|
230
|
+
<Text selectable style={styles.tipPrompt}>
|
|
231
|
+
{FIND_PROMPTS_PROMPT}
|
|
232
|
+
</Text>
|
|
233
|
+
</View>
|
|
234
|
+
</SettingsCard>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function PromptLibrary({ settings, theme, layout }: { settings: ReadySettings } & PluginSurfaceProps) {
|
|
239
|
+
const styles = useStyles(theme, layout.compact);
|
|
240
|
+
const [draft, setDraft] = useState<Draft | null>(null);
|
|
241
|
+
// Remounts the label inputs, which own their text, when a draft is discarded.
|
|
242
|
+
const [generation, setGeneration] = useState(0);
|
|
243
|
+
|
|
244
|
+
const saved = settings.values;
|
|
245
|
+
const isChanged = (candidate: Draft | null): candidate is Draft =>
|
|
246
|
+
candidate !== null &&
|
|
247
|
+
(candidate.values.display !== saved.display ||
|
|
248
|
+
JSON.stringify(candidate.values.prompts) !== JSON.stringify(saved.prompts));
|
|
249
|
+
// A draft edited back to the saved settings is no draft: show live values again.
|
|
250
|
+
const editing = isChanged(draft) ? draft : null;
|
|
251
|
+
const values = editing?.values ?? saved;
|
|
252
|
+
const prompts = values.prompts;
|
|
253
|
+
const validation = validate(values);
|
|
254
|
+
const disabled = settings.saving;
|
|
255
|
+
const inputKeyPrefix = `${editing?.revision ?? settings.revision}-${generation}`;
|
|
256
|
+
|
|
257
|
+
const editValues = (change: (current: QuickPromptsSettings) => QuickPromptsSettings): void => {
|
|
258
|
+
setDraft((current) => {
|
|
259
|
+
const base = isChanged(current) ? current : { values: saved, revision: settings.revision };
|
|
260
|
+
return { ...base, values: change(base.values) };
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
const edit = (change: (current: QuickPrompt[]) => QuickPrompt[]): void =>
|
|
264
|
+
editValues((current) => ({ ...current, prompts: change(current.prompts) }));
|
|
265
|
+
|
|
266
|
+
const discard = (): void => {
|
|
267
|
+
setDraft(null);
|
|
268
|
+
setGeneration((value) => value + 1);
|
|
269
|
+
void settings.reload();
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
const save = async (): Promise<void> => {
|
|
273
|
+
if (!editing) return;
|
|
274
|
+
const parsed = quickPromptsSettings.schema.safeParse(editing.values);
|
|
275
|
+
if (!parsed.success) return;
|
|
276
|
+
if (await settings.save(parsed.data, editing.revision)) setDraft(null);
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
return (
|
|
280
|
+
<SettingsSection title="Quick prompts">
|
|
281
|
+
<Text style={styles.intro}>
|
|
282
|
+
Quick prompts appear above every agent's composer, as separate pills or in one Prompts menu. Choosing one
|
|
283
|
+
sends the prompt to that agent as your message.
|
|
284
|
+
</Text>
|
|
285
|
+
{prompts.map((prompt, index) => (
|
|
286
|
+
<PromptEditor
|
|
287
|
+
key={prompt.id}
|
|
288
|
+
prompt={prompt}
|
|
289
|
+
index={index}
|
|
290
|
+
count={prompts.length}
|
|
291
|
+
errors={validation.fields[index] ?? {}}
|
|
292
|
+
inputKey={`${prompt.id}-${inputKeyPrefix}`}
|
|
293
|
+
disabled={disabled}
|
|
294
|
+
theme={theme}
|
|
295
|
+
styles={styles}
|
|
296
|
+
onChange={(field, value) =>
|
|
297
|
+
edit((current) => current.map((item) => (item.id === prompt.id ? { ...item, [field]: value } : item)))
|
|
298
|
+
}
|
|
299
|
+
onMove={(offset) =>
|
|
300
|
+
edit((current) => {
|
|
301
|
+
const next = [...current];
|
|
302
|
+
const [moved] = next.splice(index, 1);
|
|
303
|
+
if (moved) next.splice(index + offset, 0, moved);
|
|
304
|
+
return next;
|
|
305
|
+
})
|
|
306
|
+
}
|
|
307
|
+
onDelete={() => edit((current) => current.filter((item) => item.id !== prompt.id))}
|
|
308
|
+
/>
|
|
309
|
+
))}
|
|
310
|
+
<SettingsCard>
|
|
311
|
+
<SettingsAction
|
|
312
|
+
label={prompts.length === 0 ? "No quick prompts yet" : `${prompts.length} of ${MAX_PROMPTS} quick prompts`}
|
|
313
|
+
hint={`Labels can be up to ${LABEL_MAX_LENGTH} characters.`}
|
|
314
|
+
actionLabel="Add quick prompt"
|
|
315
|
+
disabled={disabled || prompts.length >= MAX_PROMPTS}
|
|
316
|
+
onPress={() => edit((current) => [...current, { id: newPromptId(), label: "", text: "" }])}
|
|
317
|
+
/>
|
|
318
|
+
</SettingsCard>
|
|
319
|
+
<SettingsCard>
|
|
320
|
+
<SettingsSelect
|
|
321
|
+
label="Show prompts as"
|
|
322
|
+
hint="Separate pills show one pill per prompt; one menu pill keeps them in a single menu."
|
|
323
|
+
value={values.display}
|
|
324
|
+
options={DISPLAY_OPTIONS}
|
|
325
|
+
disabled={disabled}
|
|
326
|
+
onValueChange={(display) => editValues((current) => ({ ...current, display }))}
|
|
327
|
+
/>
|
|
328
|
+
</SettingsCard>
|
|
329
|
+
{editing ? (
|
|
330
|
+
<SettingsCard>
|
|
331
|
+
<SettingsAction
|
|
332
|
+
label="Unsaved changes"
|
|
333
|
+
error={settings.saveError ?? validation.list}
|
|
334
|
+
actionLabel={disabled ? "Saving…" : "Save"}
|
|
335
|
+
disabled={disabled || !validation.valid}
|
|
336
|
+
onPress={() => void save()}
|
|
337
|
+
/>
|
|
338
|
+
<SettingsAction label="Discard changes" actionLabel="Discard" disabled={disabled} onPress={discard} />
|
|
339
|
+
</SettingsCard>
|
|
340
|
+
) : null}
|
|
341
|
+
<FindPromptsTip styles={styles} />
|
|
342
|
+
</SettingsSection>
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export function QuickPromptsSettingsScreen(props: PluginSurfaceProps) {
|
|
347
|
+
const settings = useSettings(quickPromptsSettings);
|
|
348
|
+
const style = useMemo(() => ({ color: props.theme.colors.foreground }), [props.theme]);
|
|
349
|
+
if (settings.status === "loading") return <Text style={style}>Loading quick prompts…</Text>;
|
|
350
|
+
if (settings.status !== "ready") {
|
|
351
|
+
return (
|
|
352
|
+
<SettingsSection title="Quick prompts">
|
|
353
|
+
<Text style={style}>{settings.error}</Text>
|
|
354
|
+
<SettingsCard>
|
|
355
|
+
<SettingsAction label="Try again" actionLabel="Reload" onPress={() => void settings.reload()} />
|
|
356
|
+
{settings.status === "invalid" ? (
|
|
357
|
+
<SettingsAction
|
|
358
|
+
label="Delete the saved quick prompts"
|
|
359
|
+
hint="The stored data cannot be read."
|
|
360
|
+
actionLabel="Reset"
|
|
361
|
+
onPress={() => void settings.reset()}
|
|
362
|
+
/>
|
|
363
|
+
) : null}
|
|
364
|
+
</SettingsCard>
|
|
365
|
+
</SettingsSection>
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
return <PromptLibrary settings={settings} {...props} />;
|
|
369
|
+
}
|
package/index.client.tsx
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
|
+
import { followAgents, followPrompts } from "./client/follow";
|
|
3
|
+
import { createPromptPills } from "./client/pills";
|
|
4
|
+
import { QuickPromptsSettingsScreen } from "./client/settings-screen";
|
|
5
|
+
|
|
6
|
+
const SETTINGS_SCREEN_ID = "quick-prompts";
|
|
7
|
+
|
|
8
|
+
export default function contribute(client: PluginClientContext) {
|
|
9
|
+
const removeSettings = client.addSettingsScreen({
|
|
10
|
+
id: SETTINGS_SCREEN_ID,
|
|
11
|
+
title: "Quick prompts",
|
|
12
|
+
icon: "Zap",
|
|
13
|
+
Component: QuickPromptsSettingsScreen,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const pills = createPromptPills({
|
|
17
|
+
addComposerPill: (contribution) => client.addComposerPill(contribution),
|
|
18
|
+
send: (agentId, text) => client.paseo.agents.ref(agentId).send(text),
|
|
19
|
+
openSettings: () => client.openSettings(SETTINGS_SCREEN_ID),
|
|
20
|
+
});
|
|
21
|
+
const lifetime = new AbortController();
|
|
22
|
+
followAgents(client, pills, lifetime.signal);
|
|
23
|
+
followPrompts(client, pills, lifetime.signal);
|
|
24
|
+
|
|
25
|
+
return () => {
|
|
26
|
+
lifetime.abort();
|
|
27
|
+
pills.removeAll();
|
|
28
|
+
removeSettings();
|
|
29
|
+
};
|
|
30
|
+
}
|
package/index.server.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PluginServerContext } from "@getpaseo/plugin/server";
|
|
2
|
+
import { quickPromptsSettings } from "./shared/prompts";
|
|
3
|
+
|
|
4
|
+
export default function contribute(server: PluginServerContext) {
|
|
5
|
+
server.registerSettings(quickPromptsSettings);
|
|
6
|
+
return () => {};
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paseo-quick-prompts",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Saved prompts as one-tap pills above every agent's composer.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"paseo-plugin.json",
|
|
8
|
+
"OVERVIEW.md",
|
|
9
|
+
"index.client.ts",
|
|
10
|
+
"index.client.tsx",
|
|
11
|
+
"index.server.ts",
|
|
12
|
+
"index.server.tsx",
|
|
13
|
+
"client/",
|
|
14
|
+
"server/",
|
|
15
|
+
"shared/"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"test": "vitest run"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@getpaseo/plugin": "0.11.2",
|
|
23
|
+
"@tanstack/react-query": "^5.90.11",
|
|
24
|
+
"@types/react": "~19.2.0",
|
|
25
|
+
"react": "19.1.0",
|
|
26
|
+
"react-native": "0.81.5",
|
|
27
|
+
"typescript": "^5.9.3",
|
|
28
|
+
"vitest": "^3.2.7",
|
|
29
|
+
"zod": "^4.4.3"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/kingsleydon/paseo-plugins.git",
|
|
34
|
+
"directory": "plugins/quick-prompts"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/kingsleydon/paseo-plugins/tree/main/plugins/quick-prompts#readme",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/kingsleydon/paseo-plugins/issues"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"paseo",
|
|
42
|
+
"paseo-plugin",
|
|
43
|
+
"prompts"
|
|
44
|
+
],
|
|
45
|
+
"author": "Kingsley (https://github.com/kingsleydon)"
|
|
46
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { defineSettings } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
export const MAX_PROMPTS = 20;
|
|
5
|
+
export const LABEL_MAX_LENGTH = 40;
|
|
6
|
+
export const TEXT_MAX_LENGTH = 10_000;
|
|
7
|
+
|
|
8
|
+
/** Lowercase letters and digits, so a pill id built from it is valid. */
|
|
9
|
+
const PROMPT_ID_PATTERN = /^[a-z0-9]{1,32}$/;
|
|
10
|
+
|
|
11
|
+
export const QuickPromptSchema = z.object({
|
|
12
|
+
id: z.string().regex(PROMPT_ID_PATTERN),
|
|
13
|
+
label: z
|
|
14
|
+
.string()
|
|
15
|
+
.trim()
|
|
16
|
+
.min(1, "Enter a label")
|
|
17
|
+
.max(LABEL_MAX_LENGTH, `Keep the label to ${LABEL_MAX_LENGTH} characters`),
|
|
18
|
+
text: z
|
|
19
|
+
.string()
|
|
20
|
+
.trim()
|
|
21
|
+
.min(1, "Enter the prompt")
|
|
22
|
+
.max(TEXT_MAX_LENGTH, `Keep the prompt to ${TEXT_MAX_LENGTH.toLocaleString("en-US")} characters`),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export type QuickPrompt = z.output<typeof QuickPromptSchema>;
|
|
26
|
+
|
|
27
|
+
/** How prompts appear above the composer: one pill each, or one pill that opens a menu. */
|
|
28
|
+
export const PROMPT_DISPLAYS = ["pills", "menu"] as const;
|
|
29
|
+
export type PromptDisplay = (typeof PROMPT_DISPLAYS)[number];
|
|
30
|
+
|
|
31
|
+
export const quickPromptsSettings = defineSettings({
|
|
32
|
+
id: "prompts",
|
|
33
|
+
scope: "host",
|
|
34
|
+
version: 1,
|
|
35
|
+
schema: z.object({
|
|
36
|
+
prompts: z
|
|
37
|
+
.array(QuickPromptSchema)
|
|
38
|
+
.max(MAX_PROMPTS, `Save at most ${MAX_PROMPTS} quick prompts`)
|
|
39
|
+
.refine((prompts) => new Set(prompts.map(({ id }) => id)).size === prompts.length, "Quick prompt ids must be unique")
|
|
40
|
+
.default([]),
|
|
41
|
+
// Documents saved before this field existed, or with a display this version does not know,
|
|
42
|
+
// keep separate pills and their prompts.
|
|
43
|
+
display: z.enum(PROMPT_DISPLAYS).catch("pills"),
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export type QuickPromptsSettings = z.output<typeof quickPromptsSettings.schema>;
|
|
48
|
+
|
|
49
|
+
/** The saved settings from a settings read; stored data that fails validation counts as the defaults. */
|
|
50
|
+
export function settingsFromRead(
|
|
51
|
+
result: { status: "ready"; values: unknown } | { status: "invalid" },
|
|
52
|
+
): QuickPromptsSettings {
|
|
53
|
+
const parsed = result.status === "ready" ? quickPromptsSettings.schema.safeParse(result.values).data : undefined;
|
|
54
|
+
return parsed ?? quickPromptsSettings.schema.parse({});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function newPromptId(): string {
|
|
58
|
+
return Date.now().toString(36) + Math.random().toString(36).slice(2, 8);
|
|
59
|
+
}
|