create-heresay 0.2.24 → 0.2.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-heresay",
3
- "version": "0.2.24",
3
+ "version": "0.2.26",
4
4
  "description": "Set up your own Heresay: in-app feedback that every report gets a hearing. Creates a Firebase project in your Google account and deploys the dashboard, API and SDK to it.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/release/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.24
1
+ 0.2.26
@@ -22,15 +22,18 @@ export const CHAT_LIMITS = [
22
22
  { limit: 60, windowMs: 3600_000 },
23
23
  { limit: 300, windowMs: 24 * 3600_000 },
24
24
  ];
25
+ // Descriptive, not prescriptive: chat apps flag tool text that tells the model when to ask for
26
+ // approval or what counts as sensitive ("Suspicious Instruction"). Their own rules cover that.
25
27
  const INSTRUCTIONS = [
26
28
  'Heresay is this team\'s inbox for what should change in their apps: bugs, confusing parts, improvements and ideas.',
27
- 'When the person says to send, save, log or file something to Heresay (or asks you to put an idea "in Heresay"), use send_request.',
28
- 'Write `text` as the request itself, plainly, as a teammate would read it. Put what the conversation worked out in `details`:',
29
- 'why it matters, what was considered or ruled out, examples, constraints, open questions. Never put secrets, passwords or',
30
- 'personal data about other people in either. If it isn\'t clear which app, call list_apps and ask.',
31
- 'Confirm with the person before sending if they didn\'t clearly ask to send. Requests wait for a person on the team to accept',
32
- 'them; sending does not start any work. my_requests says what happened to the ones they sent.',
29
+ 'Sending takes two steps. draft_request prepares one and returns a preview (the app, the type, the text, and the other',
30
+ 'apps); nothing is sent. send_draft sends a draft, to the app in the preview or to another one. `text` is the request as',
31
+ 'a teammate would read it; `details` is what the conversation worked out (why it matters, what was considered or ruled',
32
+ 'out, examples, constraints, open questions). A sent request stays open until someone on the team accepts it; sending',
33
+ 'does not start any work. my_requests says what happened to the ones this member sent.',
33
34
  ].join(' ');
35
+ /** How long a draft waits to be sent. */
36
+ const DRAFT_TTL_MS = 2 * 3600_000;
34
37
  const TOOLS = [
35
38
  {
36
39
  name: 'list_apps',
@@ -40,22 +43,38 @@ const TOOLS = [
40
43
  annotations: { readOnlyHint: true, openWorldHint: false },
41
44
  },
42
45
  {
43
- name: 'send_request',
44
- title: 'Send to Heresay',
45
- description: 'Send a bug, a confusing part, an improvement or an idea to one app\'s Heresay inbox, as the signed-in team member, '
46
- + 'with the context from this conversation. It waits for someone on the team to accept it. Ask the person first unless they asked you to send it.',
46
+ name: 'draft_request',
47
+ title: 'Draft a Heresay request',
48
+ description: 'Prepares a bug, a confusing part, an improvement or an idea for one app\'s Heresay inbox and returns a preview: '
49
+ + 'the app it would go to, its type and text, and the other apps. Nothing is sent. Without an app it returns the list of apps.',
47
50
  inputSchema: {
48
51
  type: 'object',
49
52
  properties: {
50
- app: { type: 'string', description: 'The app\'s id or name, from list_apps' },
53
+ app: { type: 'string', description: 'The app\'s id or name, from list_apps, when the conversation names it' },
51
54
  type: { type: 'string', enum: [...REPORT_TYPES], description: 'broken: doesn\'t work. confusing: works, but people can\'t tell how. improvement: works, could be better. idea: doesn\'t exist yet.' },
52
55
  text: { type: 'string', maxLength: LIMITS.textMax, description: 'The request in a few plain sentences, as a teammate would read it.' },
53
56
  details: { type: 'string', maxLength: LIMITS.detailsMax, description: 'Context from the conversation: why, what was considered or ruled out, examples, constraints, open questions.' },
54
57
  },
55
- required: ['app', 'type', 'text'],
58
+ required: ['type', 'text'],
56
59
  additionalProperties: false,
57
60
  },
58
- annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
61
+ annotations: { readOnlyHint: true, openWorldHint: false },
62
+ },
63
+ {
64
+ name: 'send_draft',
65
+ title: 'Send a Heresay draft',
66
+ description: 'Sends a draft from draft_request to the inbox, as the signed-in team member. `app` sends it to a different app '
67
+ + 'than the preview named. It stays open until someone on the team accepts it.',
68
+ inputSchema: {
69
+ type: 'object',
70
+ properties: {
71
+ draft_id: { type: 'string', description: 'From draft_request' },
72
+ app: { type: 'string', description: 'Another app\'s id or name, to send it there instead' },
73
+ },
74
+ required: ['draft_id'],
75
+ additionalProperties: false,
76
+ },
77
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
59
78
  },
60
79
  {
61
80
  name: 'my_requests',
@@ -132,8 +151,11 @@ async function one(m, member, via, req, deps) {
132
151
  try {
133
152
  if (name === 'list_apps')
134
153
  return rpcResult(msg.id, await listApps(deps));
135
- if (name === 'send_request')
136
- return rpcResult(msg.id, await sendRequest(args, member, via, req, deps));
154
+ // send_request is what older bridges call; it drafts too, so nothing is sent unseen.
155
+ if (name === 'draft_request' || name === 'send_request')
156
+ return rpcResult(msg.id, await draftRequest(args, member, via, deps));
157
+ if (name === 'send_draft')
158
+ return rpcResult(msg.id, await sendDraft(args, member, req, deps));
137
159
  if (name === 'my_requests')
138
160
  return rpcResult(msg.id, await myRequests(args, member, req, deps));
139
161
  return rpcError(msg.id, -32602, `Unknown tool: ${String(name)}`);
@@ -167,14 +189,52 @@ async function findApp(v, deps) {
167
189
  return hit;
168
190
  }
169
191
  const dashboardLink = (req, deps, p) => `${baseUrl(req, deps)}/app/#/apps/${p.id}`;
170
- async function sendRequest(a, member, via, req, deps) {
171
- const project = await findApp(a.app, deps);
192
+ const appNames = (ps) => ps.map((p) => `${p.name} (${p.platform})`).join(', ');
193
+ /** A preview, nothing sent: which app, what type, the text, and where else it could go. */
194
+ async function draftRequest(a, member, via, deps) {
172
195
  if (!isReportType(a.type))
173
196
  throw new ToolError(`type must be one of ${REPORT_TYPES.join(', ')}.`);
174
197
  const text = str(a.text, LIMITS.textMax);
175
198
  if (!text)
176
199
  throw new ToolError('Say what the request is, in text.');
177
200
  const details = str(a.details, LIMITS.detailsMax);
201
+ const all = (await deps.store.listProjects()).sort((x, y) => x.created_at.localeCompare(y.created_at));
202
+ if (!str(a.app, 100)) {
203
+ return result(`No app named, so no draft yet. The apps on this Heresay: ${appNames(all) || 'none yet'}. Which one is it for?`, { draft: null, apps: all.map((p) => ({ id: p.id, name: p.name, platform: p.platform })) });
204
+ }
205
+ const project = await findApp(a.app, deps);
206
+ const id = createHash('sha256').update(`${member.email}${deps.now()}${Math.random()}`).digest('hex').slice(0, 24);
207
+ await deps.store.putAuth({
208
+ kind: 'draft', id, expires_at: new Date(deps.now() + DRAFT_TTL_MS).toISOString(),
209
+ data: { email: member.email, project_id: project.id, type: a.type, text, details, via },
210
+ });
211
+ const others = all.filter((p) => p.id !== project.id);
212
+ return result([
213
+ `Draft, not sent yet. App: ${project.name} (${project.platform}). Type: ${a.type}.`,
214
+ `Text: ${text}`,
215
+ details ? `Details: ${details}` : null,
216
+ others.length ? `Other apps it could go to instead: ${appNames(others)}.` : null,
217
+ `send_draft with draft_id ${id} sends it${others.length ? ' (with app set to send it elsewhere)' : ''}. Drafts last two hours.`,
218
+ ].filter(Boolean).join('\n'), {
219
+ draft_id: id, sent: false, app: project.name, type: a.type, text, details,
220
+ other_apps: others.map((p) => ({ id: p.id, name: p.name, platform: p.platform })),
221
+ });
222
+ }
223
+ async function sendDraft(a, member, req, deps) {
224
+ const id = str(a.draft_id, 64);
225
+ const d = id ? await deps.store.getAuth('draft', id) : null;
226
+ if (!d || String(d.data.email).toLowerCase() !== member.email.toLowerCase() || Date.parse(d.expires_at ?? '') < deps.now()) {
227
+ throw new ToolError('That draft doesn\'t exist, has expired or was already sent. Make a new one with draft_request.');
228
+ }
229
+ const project = a.app ? await findApp(a.app, deps) : await deps.store.getProject(String(d.data.project_id));
230
+ if (!project)
231
+ throw new ToolError('The draft\'s app was deleted. Name another app.');
232
+ // Once only, however many times it's called.
233
+ if (!(await deps.store.takeAuth('draft', id)))
234
+ throw new ToolError('That draft was already sent.');
235
+ return createChatReport(project, d.data.type, String(d.data.text), d.data.details ?? null, member, String(d.data.via ?? 'a chat app'), req, deps);
236
+ }
237
+ async function createChatReport(project, type, text, details, member, via, req, deps) {
178
238
  const now = deps.now();
179
239
  for (const l of CHAT_LIMITS) {
180
240
  const start = Math.floor(now / l.windowMs) * l.windowMs;
@@ -185,7 +245,7 @@ async function sendRequest(a, member, via, req, deps) {
185
245
  const at = new Date(now).toISOString();
186
246
  const report = {
187
247
  id: `r_${createHash('sha256').update(`${member.email}${now}${Math.random()}`).digest('base64url').slice(0, 16)}`,
188
- project_id: project.id, device_id: chatDevice(member.email), type: a.type, text,
248
+ project_id: project.id, device_id: chatDevice(member.email), type, text,
189
249
  source: 'chat', from_member: member.email, via: str(via, 80), details,
190
250
  context: {
191
251
  route: null, app_version: null, platform: 'chat', os: null, browser: null,
@@ -1,3 +1,3 @@
1
1
  /** The Heresay release. Bumped by the release script; the CLI and /v1/health report it. */
2
- export const VERSION = '0.2.24';
2
+ export const VERSION = '0.2.26';
3
3
  //# sourceMappingURL=version.js.map