@workover/cli 0.26.0 → 0.29.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/bin/workover.mjs +2312 -5
- package/contacts.mjs +1561 -0
- package/domains.mjs +417 -0
- package/email-studio.mjs +829 -0
- package/feedback-board.mjs +321 -0
- package/journeys.mjs +409 -0
- package/lib.mjs +56 -0
- package/package.json +20 -1
- package/support-agent-tests.mjs +424 -0
- package/support-config.mjs +302 -0
- package/support-email.mjs +458 -0
- package/support-fields.mjs +294 -0
- package/support-freshdesk.mjs +176 -0
- package/support-inbox.mjs +313 -0
- package/support-label-rules.mjs +136 -0
- package/support-labels.mjs +244 -0
- package/support-outcomes.mjs +276 -0
- package/support-outside-bot.mjs +145 -0
- package/support-setup.mjs +660 -0
- package/support-signatures.mjs +156 -0
- package/support-sources.mjs +233 -0
- package/support-walter.mjs +310 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
// Feedback's posts from a terminal: `workover requests ...` and the MCP server's `workover_feedback_*`
|
|
2
|
+
// tools (WO-1752, round 3). Not to be confused with `workover feedback`, which reports a problem with
|
|
3
|
+
// Workover itself.
|
|
4
|
+
//
|
|
5
|
+
// THE SAME FILE ships in @workover/cli (apps/cli/feedback-board.mjs) and @workover/mcp
|
|
6
|
+
// (apps/mcp/feedback-board.mjs), because the two packages are published separately and neither may
|
|
7
|
+
// depend on the other. `apps/mcp/feedback-board.test.mjs` fails when the copies differ.
|
|
8
|
+
//
|
|
9
|
+
// List posts (by votes, newest, most valuable by who asked, or trending), read one with its voters
|
|
10
|
+
// and status history, post a request, vote, and move a post's status. Moving to Planned, In progress
|
|
11
|
+
// or Shipped tells its voters (a Messenger message and an email to customers, an in-app notification
|
|
12
|
+
// to teammates) unless `notify` is false; `preview` says who would be told and the exact words
|
|
13
|
+
// without moving it. Each call goes to a route open to any `workover login` token; moving a status is
|
|
14
|
+
// the workspace owner's or an admin's. Voting and moving to the same status again change nothing,
|
|
15
|
+
// and nobody is told twice about one status.
|
|
16
|
+
//
|
|
17
|
+
// `call(path, { method, body })` does the requests and resolves the parsed JSON, or throws an Error
|
|
18
|
+
// whose `.status` is the HTTP status and whose message is the API's own sentence. The renderers
|
|
19
|
+
// return lines, for a terminal or an MCP text result alike.
|
|
20
|
+
|
|
21
|
+
import { apiError, resolveWorkspace } from './site-setup.mjs';
|
|
22
|
+
|
|
23
|
+
export const FEEDBACK_STATUSES = ['under_review', 'planned', 'in_progress', 'shipped'];
|
|
24
|
+
export const FEEDBACK_SORTS = ['top', 'new', 'weighted', 'trending'];
|
|
25
|
+
const STATUS_LABEL = {
|
|
26
|
+
under_review: 'Under review',
|
|
27
|
+
planned: 'Planned',
|
|
28
|
+
in_progress: 'In progress',
|
|
29
|
+
shipped: 'Shipped',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const base = (ws) => `/workspace/${encodeURIComponent(ws.id)}/feedback`;
|
|
33
|
+
|
|
34
|
+
/** A post id from a number, "#12", or a post link (.../feedback/posts/12). */
|
|
35
|
+
export function postIdOf(ref) {
|
|
36
|
+
const raw = String(ref ?? '').trim();
|
|
37
|
+
const m = raw.match(/(?:posts\/|#)?(\d+)\/?$/);
|
|
38
|
+
const n = m ? Number(m[1]) : NaN;
|
|
39
|
+
if (!Number.isInteger(n) || n < 1) throw apiError(400, 'Name the post by its id (12) or its link.');
|
|
40
|
+
return n;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A built-in status from its key or its label ("In progress", "in-progress"), whatever the case,
|
|
45
|
+
* or a workspace's own status key (`c_` and 8 hex, as the app makes them).
|
|
46
|
+
*/
|
|
47
|
+
export function statusOf(raw) {
|
|
48
|
+
const t = String(raw ?? '').trim();
|
|
49
|
+
if (/^c_[0-9a-f]{8}$/.test(t)) return t;
|
|
50
|
+
const s = t.toLowerCase().replace(/[\s-]+/g, '_');
|
|
51
|
+
if (!FEEDBACK_STATUSES.includes(s))
|
|
52
|
+
throw apiError(400, `status is one of ${FEEDBACK_STATUSES.join(', ')}, or a workspace's own status.`);
|
|
53
|
+
return s;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const norm = (x) => String(x ?? '').trim().toLowerCase().replace(/[\s_-]+/g, ' ');
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A status as the workspace names it: its key, or its label as the workspace renamed it ("Live")
|
|
60
|
+
* or added it ("Beta"). Falls back to the built-in keys and labels.
|
|
61
|
+
*/
|
|
62
|
+
async function resolveStatus(call, ws, raw) {
|
|
63
|
+
const { statuses = [] } = await call(`${base(ws)}/boards`);
|
|
64
|
+
const hit = statuses.find((x) => x.key === String(raw).trim() || norm(x.label) === norm(raw));
|
|
65
|
+
if (hit) return hit.key;
|
|
66
|
+
try {
|
|
67
|
+
return statusOf(raw);
|
|
68
|
+
} catch {
|
|
69
|
+
const names = statuses.map((x) => x.label);
|
|
70
|
+
throw apiError(400, `There is no status "${String(raw).trim()}". Statuses: ${names.length ? names.join(', ') : FEEDBACK_STATUSES.join(', ')}.`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** A board by its id or name, from the workspace's boards. */
|
|
75
|
+
async function boardOf(call, ws, ref) {
|
|
76
|
+
const { boards = [] } = await call(`${base(ws)}/boards`);
|
|
77
|
+
if (ref === undefined || ref === null || String(ref).trim() === '') {
|
|
78
|
+
if (boards.length === 1) return boards[0];
|
|
79
|
+
if (!boards.length) throw apiError(404, 'This workspace has no Feedback board yet. An admin makes one in Feedback.');
|
|
80
|
+
throw apiError(400, `Which board? ${boards.map((b) => `${b.id} (${b.name})`).join(', ')}.`);
|
|
81
|
+
}
|
|
82
|
+
const raw = String(ref).trim();
|
|
83
|
+
const hit = boards.find((b) => String(b.id) === raw || b.name.toLowerCase() === raw.toLowerCase());
|
|
84
|
+
if (!hit) throw apiError(404, `There is no board "${raw}". Boards: ${boards.map((b) => b.name).join(', ') || 'none'}.`);
|
|
85
|
+
return hit;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Posts, with the list's own filters. */
|
|
89
|
+
export async function listPosts(call, { workspace, board, status, sort, q, offset } = {}) {
|
|
90
|
+
const ws = await resolveWorkspace(call, workspace);
|
|
91
|
+
const params = new URLSearchParams();
|
|
92
|
+
if (board !== undefined && board !== null && board !== '') params.set('board', String((await boardOf(call, ws, board)).id));
|
|
93
|
+
if (status) params.set('status', await resolveStatus(call, ws, status));
|
|
94
|
+
if (sort) {
|
|
95
|
+
const s = String(sort).toLowerCase();
|
|
96
|
+
if (!FEEDBACK_SORTS.includes(s)) throw apiError(400, `sort is one of ${FEEDBACK_SORTS.join(', ')}.`);
|
|
97
|
+
params.set('sort', s);
|
|
98
|
+
}
|
|
99
|
+
if (q && String(q).trim()) params.set('q', String(q).trim());
|
|
100
|
+
if (offset) params.set('offset', String(offset));
|
|
101
|
+
const qs = params.toString();
|
|
102
|
+
const res = await call(`${base(ws)}/posts${qs ? `?${qs}` : ''}`);
|
|
103
|
+
return { workspace: ws, ...res };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** One post, with its voters, conversations and status history. */
|
|
107
|
+
export async function getPost(call, { workspace, post }) {
|
|
108
|
+
const ws = await resolveWorkspace(call, workspace);
|
|
109
|
+
const res = await call(`${base(ws)}/posts/${postIdOf(post)}`);
|
|
110
|
+
return { workspace: ws, post: res };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Post a request to a board, as the signed-in person (who counts as its first vote). */
|
|
114
|
+
export async function createPost(call, { workspace, board, title, body }) {
|
|
115
|
+
const t = String(title ?? '').trim();
|
|
116
|
+
if (!t) throw apiError(400, 'Give the request a title.');
|
|
117
|
+
const ws = await resolveWorkspace(call, workspace);
|
|
118
|
+
const b = await boardOf(call, ws, board);
|
|
119
|
+
const res = await call(`${base(ws)}/posts`, {
|
|
120
|
+
method: 'POST',
|
|
121
|
+
body: { boardId: b.id, title: t, ...(body ? { body: String(body) } : {}) },
|
|
122
|
+
});
|
|
123
|
+
return { workspace: ws, post: res };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Vote for a post (or take the vote back with `remove`). Safe to repeat. */
|
|
127
|
+
export async function votePost(call, { workspace, post, remove = false }) {
|
|
128
|
+
const ws = await resolveWorkspace(call, workspace);
|
|
129
|
+
const res = await call(`${base(ws)}/posts/${postIdOf(post)}/vote`, { method: remove ? 'DELETE' : 'PUT' });
|
|
130
|
+
return { workspace: ws, ...res };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Move a post's status. With `preview`, nothing moves: the answer is who would be told and what
|
|
135
|
+
* they would read. `notify: false` moves it without telling anyone; `note` goes under the update.
|
|
136
|
+
*/
|
|
137
|
+
export async function setStatus(call, { workspace, post, status, notify = true, note, preview = false }) {
|
|
138
|
+
const ws = await resolveWorkspace(call, workspace);
|
|
139
|
+
const id = postIdOf(post);
|
|
140
|
+
const s = await resolveStatus(call, ws, status);
|
|
141
|
+
const n = note === undefined || note === null ? '' : String(note).trim();
|
|
142
|
+
if (n.length > 1000) throw apiError(400, 'A note is at most 1000 characters.');
|
|
143
|
+
if (preview) {
|
|
144
|
+
const qs = new URLSearchParams({ status: s, ...(n ? { note: n } : {}) });
|
|
145
|
+
const res = await call(`${base(ws)}/posts/${id}/status-preview?${qs}`);
|
|
146
|
+
return { workspace: ws, preview: res };
|
|
147
|
+
}
|
|
148
|
+
const res = await call(`${base(ws)}/posts/${id}`, {
|
|
149
|
+
method: 'PATCH',
|
|
150
|
+
body: { status: s, notifyVoters: notify !== false, ...(n && notify !== false ? { note: n } : {}) },
|
|
151
|
+
});
|
|
152
|
+
return { workspace: ws, post: res };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
156
|
+
const label = (s) => STATUS_LABEL[s] ?? s;
|
|
157
|
+
|
|
158
|
+
export function renderPostLine(p) {
|
|
159
|
+
const score = p.score == null ? '' : p.companyCount != null ? `, weighted ${round(p.score)}` : `, trending ${round(p.score)}`;
|
|
160
|
+
return ` ${String(p.id).padStart(4)} ${p.title} (${label(p.status)}; ${plural(p.voteCount, 'vote')}${score}; ${p.boardName})`;
|
|
161
|
+
}
|
|
162
|
+
const round = (n) => String(Math.round(n * 10) / 10);
|
|
163
|
+
|
|
164
|
+
export function renderPosts(res) {
|
|
165
|
+
const posts = res.posts ?? [];
|
|
166
|
+
if (!posts.length) return ['', ' No posts match.', ''];
|
|
167
|
+
const out = ['', ...posts.map(renderPostLine)];
|
|
168
|
+
if ((res.total ?? posts.length) > posts.length + (res.offset ?? 0))
|
|
169
|
+
out.push('', ` ${posts.length} of ${res.total}. Pass --offset ${(res.offset ?? 0) + posts.length} for more.`);
|
|
170
|
+
out.push('');
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function renderPost(p) {
|
|
175
|
+
const out = ['', ` #${p.id} ${p.title}`, ` ${label(p.status)} · ${plural(p.voteCount, 'vote')} · ${p.boardName}`];
|
|
176
|
+
if (p.mergedInto) out.push(` Merged into #${p.mergedInto.id} ${p.mergedInto.title}.`);
|
|
177
|
+
if (p.score != null) out.push(` Weighted ${round(p.score)} across ${plural(p.companyCount ?? 0, 'company', 'companies')}.`);
|
|
178
|
+
if (p.body) out.push('', ...String(p.body).split('\n').map((l) => ` ${l}`));
|
|
179
|
+
const voters = p.voters ?? [];
|
|
180
|
+
if (voters.length) {
|
|
181
|
+
out.push('', ' Voters:');
|
|
182
|
+
for (const v of voters) {
|
|
183
|
+
const who = v.name || v.email || v.key || 'Someone';
|
|
184
|
+
const bits = [v.company, v.plan, v.unsubscribed ? 'no updates' : null].filter(Boolean);
|
|
185
|
+
out.push(` ${who}${bits.length ? ` (${bits.join(', ')})` : ''}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const updates = p.updates ?? [];
|
|
189
|
+
if (updates.length) {
|
|
190
|
+
out.push('', ' Updates:');
|
|
191
|
+
for (const u of updates) {
|
|
192
|
+
const t = u.told ?? {};
|
|
193
|
+
const told = (t.messenger ?? 0) + (t.email ?? 0) + (t.inApp ?? 0);
|
|
194
|
+
const how = u.notified === false ? 'nobody told' : `${plural(told, 'message', 'messages')} sent`;
|
|
195
|
+
out.push(` ${String(u.createdAt ?? '').slice(0, 10)} ${label(u.fromStatus)} to ${label(u.toStatus)} (${how})`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
out.push('');
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function renderPreview(p) {
|
|
203
|
+
const c = p.counts ?? {};
|
|
204
|
+
const out = ['', ` Moving to ${label(p.status)} would tell:`];
|
|
205
|
+
if (!p.notifies) out.push(' Nobody: this status tells no one.');
|
|
206
|
+
else {
|
|
207
|
+
out.push(` ${plural(c.messenger ?? 0, 'Messenger message')}, ${plural(c.email ?? 0, 'email')}, ${plural(c.inApp ?? 0, 'in-app notification')}.`);
|
|
208
|
+
if (c.alreadyTold) out.push(` ${c.alreadyTold} already told about this status.`);
|
|
209
|
+
if (c.skipped) out.push(` ${c.skipped} not told (unsubscribed, no way to reach, or you).`);
|
|
210
|
+
out.push('', ` ${p.message?.subject ?? ''}`, ...String(p.message?.text ?? '').split('\n').map((l) => ` | ${l}`));
|
|
211
|
+
}
|
|
212
|
+
out.push('');
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const WORKSPACE = {
|
|
217
|
+
type: 'string',
|
|
218
|
+
description: 'The workspace, by slug or id. Needed only when the account has more than one.',
|
|
219
|
+
};
|
|
220
|
+
const POST_REF = { type: 'string', description: 'The post, by its id (12) or its link.' };
|
|
221
|
+
|
|
222
|
+
/** The MCP server's Feedback tools (index.mjs). */
|
|
223
|
+
export const FEEDBACK_BOARD_TOOL_DEFS = [
|
|
224
|
+
{
|
|
225
|
+
name: 'workover_feedback_posts',
|
|
226
|
+
description:
|
|
227
|
+
"Feedback's posts (feature requests): each with its id, status, votes and board. Sort by votes (top), newest (new), most valuable by who asked (weighted: each company once, by plan and revenue the site signed) or recent votes (trending). Filter by board, status or words.",
|
|
228
|
+
inputSchema: {
|
|
229
|
+
type: 'object',
|
|
230
|
+
properties: {
|
|
231
|
+
workspace: WORKSPACE,
|
|
232
|
+
board: { type: 'string', description: 'A board, by id or name.' },
|
|
233
|
+
status: { type: 'string', description: "A status by key (under_review, planned, in_progress, shipped, or a workspace's own c_ key) or by the name the workspace shows (\"Live\")." },
|
|
234
|
+
sort: { type: 'string', enum: FEEDBACK_SORTS },
|
|
235
|
+
q: { type: 'string', description: 'Words in the title or body.' },
|
|
236
|
+
offset: { type: 'number' },
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: 'workover_feedback_post',
|
|
242
|
+
description:
|
|
243
|
+
'One Feedback post: its body, status, votes, voters (with company and plan when the site signed them), the weighted score, and its status updates with how many voters each told.',
|
|
244
|
+
inputSchema: { type: 'object', properties: { workspace: WORKSPACE, post: POST_REF }, required: ['post'] },
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: 'workover_feedback_create_post',
|
|
248
|
+
description:
|
|
249
|
+
'Post a feature request to a Feedback board, as the signed-in person, who counts as its first vote. Check workover_feedback_posts for the same request first: a vote on it beats a duplicate.',
|
|
250
|
+
inputSchema: {
|
|
251
|
+
type: 'object',
|
|
252
|
+
properties: {
|
|
253
|
+
workspace: WORKSPACE,
|
|
254
|
+
board: { type: 'string', description: 'The board, by id or name. Needed when there is more than one.' },
|
|
255
|
+
title: { type: 'string' },
|
|
256
|
+
body: { type: 'string', description: 'Optional: what it is for, and who asked.' },
|
|
257
|
+
},
|
|
258
|
+
required: ['title'],
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
name: 'workover_feedback_vote',
|
|
263
|
+
description: 'Vote for a Feedback post as the signed-in person, or take the vote back (remove: true). Safe to repeat.',
|
|
264
|
+
inputSchema: {
|
|
265
|
+
type: 'object',
|
|
266
|
+
properties: { workspace: WORKSPACE, post: POST_REF, remove: { type: 'boolean' } },
|
|
267
|
+
required: ['post'],
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
name: 'workover_feedback_set_status',
|
|
272
|
+
description:
|
|
273
|
+
"Move a Feedback post to another status: under_review, planned, in_progress, shipped, or one of the workspace's own statuses, by key or by name. Planned, In progress and Shipped tell its voters (customers by Messenger and email, teammates in the app), once per status, unless notify is false. Run with preview: true first and show the person who would be told and the words; move it only when they agree. Owners and admins.",
|
|
274
|
+
inputSchema: {
|
|
275
|
+
type: 'object',
|
|
276
|
+
properties: {
|
|
277
|
+
workspace: WORKSPACE,
|
|
278
|
+
post: POST_REF,
|
|
279
|
+
status: { type: 'string', description: "A status by key (under_review, planned, in_progress, shipped, or a workspace's own c_ key) or by the name the workspace shows (\"Live\")." },
|
|
280
|
+
notify: { type: 'boolean', description: 'Tell the voters (default true).' },
|
|
281
|
+
note: { type: 'string', description: 'Optional, up to 1000 characters, under the update.' },
|
|
282
|
+
preview: { type: 'boolean', description: 'Say who would be told and what they would read, without moving it.' },
|
|
283
|
+
},
|
|
284
|
+
required: ['post', 'status'],
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
];
|
|
288
|
+
|
|
289
|
+
/** The Feedback tools' names, for the MCP dispatcher. */
|
|
290
|
+
export const FEEDBACK_BOARD_TOOLS = new Set(FEEDBACK_BOARD_TOOL_DEFS.map((t) => t.name));
|
|
291
|
+
|
|
292
|
+
/** One Feedback tool, run: the lines to answer with. Throws as `call` does. */
|
|
293
|
+
export async function runFeedbackBoardTool(call, name, args = {}) {
|
|
294
|
+
const workspace = args.workspace === undefined || args.workspace === null ? undefined : String(args.workspace);
|
|
295
|
+
if (name === 'workover_feedback_posts')
|
|
296
|
+
return renderPosts(
|
|
297
|
+
await listPosts(call, { workspace, board: args.board, status: args.status, sort: args.sort, q: args.q, offset: args.offset }),
|
|
298
|
+
);
|
|
299
|
+
if (name === 'workover_feedback_post') return renderPost((await getPost(call, { workspace, post: args.post })).post);
|
|
300
|
+
if (name === 'workover_feedback_create_post') {
|
|
301
|
+
const res = await createPost(call, { workspace, board: args.board, title: args.title, body: args.body });
|
|
302
|
+
return ['', ` ✓ Posted #${res.post.id}: ${res.post.title}`, ''];
|
|
303
|
+
}
|
|
304
|
+
if (name === 'workover_feedback_vote') {
|
|
305
|
+
const res = await votePost(call, { workspace, post: args.post, remove: args.remove === true });
|
|
306
|
+
return ['', ` ✓ ${args.remove === true ? 'Vote taken back' : 'Voted'}. It has ${plural(res.voteCount ?? 0, 'vote')}.`, ''];
|
|
307
|
+
}
|
|
308
|
+
if (name === 'workover_feedback_set_status') {
|
|
309
|
+
const res = await setStatus(call, {
|
|
310
|
+
workspace,
|
|
311
|
+
post: args.post,
|
|
312
|
+
status: args.status,
|
|
313
|
+
notify: args.notify !== false,
|
|
314
|
+
note: args.note,
|
|
315
|
+
preview: args.preview === true,
|
|
316
|
+
});
|
|
317
|
+
if (res.preview) return renderPreview(res.preview);
|
|
318
|
+
return ['', ` ✓ #${res.post.id} is ${label(res.post.status)}.${args.notify === false ? ' Nobody was told.' : ' Its voters are being told.'}`, ''];
|
|
319
|
+
}
|
|
320
|
+
throw apiError(400, `Unknown tool: ${name}`);
|
|
321
|
+
}
|