@supersuit/suggest-a-change 0.2.5 → 0.3.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/CHANGELOG.md +5 -0
- package/README.md +2 -1
- package/dist/client/adapters.d.ts +1 -1
- package/dist/client/default-field.js +1 -1
- package/dist/client/mine.js +2 -0
- package/dist/client/sheet.js +1 -1
- package/dist/github/compose.d.ts +7 -2
- package/dist/github/compose.js +4 -1
- package/dist/github/filer.d.ts +3 -0
- package/dist/github/index.d.ts +2 -2
- package/dist/github/index.js +1 -1
- package/dist/github/relay.d.ts +27 -0
- package/dist/github/relay.js +48 -3
- package/package.json +1 -1
- package/src/client/adapters.ts +1 -1
- package/src/client/default-field.tsx +1 -1
- package/src/client/mine.tsx +2 -0
- package/src/client/sheet.tsx +1 -1
- package/src/github/compose.ts +10 -3
- package/src/github/filer.ts +3 -1
- package/src/github/index.ts +2 -2
- package/src/github/relay.ts +57 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.0 (2026-11-01)
|
|
4
|
+
|
|
5
|
+
- **The relay transcribes voice notes.** `createSuggestionRelay({ transcribe })` takes a transcriber, `({ name, mimeType, bytes, staged? }, { signal }) => Promise<string>`, and calls it for each voice note a `file` or `follow-up` brings with no `transcript`, before the privacy catch, so the transcript is caught like the words. A report with only a voice note is now titled from the transcript's first sentence instead of "Suggestion from <app>", under "Voice note (transcribed automatically)" rather than a claim about the owner's Mac. A transcriber that fails, hears nothing, or takes longer than `transcribeTimeoutMs` (default 25 s) never stops the filing: the issue files with the recording and says in plain words why there is no transcript, never the transcriber's error. `capabilities` answers `transcribes`; `RelayCapabilities`, `ComposeOptions.transcriptBy` and `transcriptNote` are new. Earned when voice-only suggestions reached GitHub as "Not transcribed." after the receiving Mac stopped writing transcripts.
|
|
6
|
+
- **My suggestions sets nothing once it is gone.** A report marked seen starts a recount; if the screen unmounted while that recount was reading the seen record, its late answer still set state, which threw `window is not defined` inside React when the page had been torn down (seen 2026-10-29 as an unhandled rejection failing the Helm's vitest run under load). Unmounting now retires every load and recount still in flight, as switching account already did.
|
|
7
|
+
|
|
3
8
|
## 0.2.5 (2026-10-26)
|
|
4
9
|
|
|
5
10
|
- **A tap on the microphone records.** `DefaultField` was hold-only: on a tap the release ended the take before the microphone had answered, so nothing was recorded and nothing said to hold (seen on iPhone Safari). Now a press shorter than 350 ms starts a take that keeps recording until the next tap (or the time limit), and a longer press records until it is let go. Leaving the button, or a pointer the browser cancels (iOS Safari does when its permission prompt appears), never ends a tapped take. `startTake` is still called synchronously inside the press, with nothing awaited before it. While recording the dot turns to a stop square and pulses (under `prefers-reduced-motion: no-preference`).
|
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ const adapters: Adapters = {
|
|
|
52
52
|
|
|
53
53
|
`SuggestEntry` also takes `className` and `role` (for example `role="menuitem"` when a host shows it as a menu row); no role is set by default. My suggestions and the detail view keep their last answer from the app on the phone (module-owned IndexedDB, keyed by app and account like a draft), draw it at once with a quiet "Updating" line, and replace it when the app answers; if the app cannot be reached they keep the saved rows and say so. An adapter tells a refusal from an unreachable app: `mine()` and `one()` throw an error with `refused: true` or a `status` of 401, 403 or 404 for a refusal (the saved copy is then deleted), and anything else thrown is unreachable. Saved reports the list no longer holds are pruned, and signing out clears them. A first open with nothing saved shows "Loading".
|
|
54
54
|
|
|
55
|
-
The entry also keeps the phone's outbox moving while it is mounted (a report sent with the Mac away goes when it is back, with the sheet closed); a host with no always-mounted entry renders `<KeepSending adapters={adapters} />` once, high in the app. The entry carries `data-suggest-entry` (the attribute the screen check looks for; see "The check" below). Signed out, it opens nothing and says why. The receipt says "Got it" only after the adapter has answered `done` for the report and every attachment; until then it says the report is on the phone. Every text field the module renders sits in a `[data-voice-field]` container with a `[data-voice-control]`; a host's `Field` slot must keep that shape (it receives `FieldProps`, which is the Helm's voice field props). A voice note alone is a whole report: the recording is kept and uploaded as a part, and
|
|
55
|
+
The entry also keeps the phone's outbox moving while it is mounted (a report sent with the Mac away goes when it is back, with the sheet closed); a host with no always-mounted entry renders `<KeepSending adapters={adapters} />` once, high in the app. The entry carries `data-suggest-entry` (the attribute the screen check looks for; see "The check" below). Signed out, it opens nothing and says why. The receipt says "Got it" only after the adapter has answered `done` for the report and every attachment; until then it says the report is on the phone. Every text field the module renders sits in a `[data-voice-field]` container with a `[data-voice-control]`; a host's `Field` slot must keep that shape (it receives `FieldProps`, which is the Helm's voice field props). A voice note alone is a whole report: the recording is kept and uploaded as a part, and whoever receives it writes the transcript (a relay given `transcribe`, see below, or the owner's Mac). `DefaultField` puts its microphone inside the text box (bottom right of a text area, centred at the right of a one-line input, a 44px target, with the text kept clear of it). A tap starts a take that records until the next tap or the time limit; a press held past a tap records until it is let go; leaving the button or a pointer the browser cancels (iOS Safari's microphone prompt) never ends a tapped take. The recorder is asked inside the press with nothing awaited first, so iOS Safari counts the microphone request as part of the gesture. A host's own `Field` should follow the same two rules.
|
|
56
56
|
|
|
57
57
|
Styling: structure only, class names prefixed `sac-`. `@supersuit/suggest-a-change/styles.css` is optional defaults (16px inputs so iOS does not zoom, 44px touch targets, safe-area padding on the sheet). Re-skin it with these custom properties:
|
|
58
58
|
|
|
@@ -385,6 +385,7 @@ await relay.status([{ repo: "acme/notes", number: got.number }]); // [{ repo, nu
|
|
|
385
385
|
|
|
386
386
|
- **`file`** `{ repo, app?, report, transcript?, files: [{ name, type, bytes (base64) } | { name, type, staged: name }], redacted? }` answers `{ number, url }`. The relay checks the report against the contract and each file against what the report declares, runs the privacy catch itself, saves the files to `suggestion-attachments`, then opens the issue **as the App**, filed by the name `identity()` gives (never the account id, and never a name in the request), with the role and the contact from `identity()` too and the app's name and `app:<label>` from the relay's `apps` table by the request's `app` id (an id not in the table is 400 "unknown app"; with no table no request names an app, and the issue says "in an app" with no app label); the contact only when the report carries `who.contact` (the person left it ticked). At most ten labels. A credential refuses with 422 naming the kind and the field, never the text, whatever `redacted` says. Any other hit refuses with 409 `{ held: true, hits: [{ kind, field }] }` until the filer sends again with `redacted: true`, saying they chose to file without the flagged part; the relay then redacts what it found itself, so raw text is never filed on the filer's word. The catch reads every string that would reach the issue (where, every diagnostic, the context, the trail, the names, the handle), after folding look-alike letters and removing invisible characters. A repeat of the same report answers the same issue; another identity using that report id is 409.
|
|
387
387
|
- **`follow-up`** `{ repo, number, reportId, words, transcript?, files?, redacted? }` adds a comment, only for the identity that filed that report through this relay (anyone else, 403). The same privacy catch runs.
|
|
388
|
+
- **Transcribing voice notes.** Pass `transcribe: async ({ name, mimeType, bytes, staged? }, { signal }) => string` and the relay writes the transcript of every voice note a `file` or `follow-up` brings with no `transcript` (a staged note's bytes are already read; `staged` is its key, for a host that would rather sign a read link). It runs before the privacy catch, so the transcript is caught and redacted like the words; the issue's heading says "Voice note (transcribed automatically)", and a report with no words takes its title from the transcript's first sentence instead of "Suggestion from <app>". All of a request's notes are transcribed at once within `transcribeTimeoutMs` (default `TRANSCRIBE_TIMEOUT_MS`, 25 s, inside a 60 s serverless limit); `signal` aborts when the relay stops waiting. A transcriber that throws, returns nothing, or is too slow never stops the filing: the issue files with the recording and one plain sentence of why (`TRANSCRIPT_MISSING`: the service did not answer in time, failed or refused the recording, or heard no speech), never the transcriber's own error text. A transcript the request carries is used as it is. `capabilities` answers `transcribes: true` when the relay has a transcriber, which is what a host sets the sheet's `Destination.transcribes` from, so the list promises a transcript only when one will be made.
|
|
388
389
|
- **`status`** `{ items: [{ repo, number }] }` answers `{ items: [{ repo, number, status, reason? }] }`, only for issues this identity filed (anything else, 403).
|
|
389
390
|
- **`attach`** is for a filer who opened the issue themselves but cannot push. Reading the issue is the proof they could file there: it must exist, be an issue, be open or closed within a week, and END with the composer's own `## Filed by` line for that report ("Report <id>" anywhere else proves nothing). And a report belongs to the first identity that files or attaches for it: anyone else attaching to it is 403. An issue the relay filed takes files only from the identity that filed it; an issue someone opened themselves takes them only when its author's login is the `githubLogin` that `identity()` vouches for, and nothing is claimed until that proof holds. A request lists each file once and no more of each kind than a report may carry; a follow-up is composed and measured before any file is written, and holds to the report's caps like `attach`.
|
|
390
391
|
|
|
@@ -42,7 +42,7 @@ export interface FieldProps {
|
|
|
42
42
|
placeholder?: string;
|
|
43
43
|
multiline?: boolean;
|
|
44
44
|
type?: 'text' | 'search';
|
|
45
|
-
/** Gets each finished take. The sheet keeps the recording;
|
|
45
|
+
/** Gets each finished take. The sheet keeps the recording; the transcript is written where it is received (a relay with `transcribe`, or the owner's Mac). */
|
|
46
46
|
upload?: HeardUpload;
|
|
47
47
|
onHeard?(h: {
|
|
48
48
|
audio: string;
|
|
@@ -4,7 +4,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
4
4
|
// INSIDE the box (bottom right; centred at the right of a one-line input), in one [data-voice-field]
|
|
5
5
|
// container with nothing else typeable in it. A take is
|
|
6
6
|
// recorded with the module's recorder (written to the phone's database as it is made). Transcription is
|
|
7
|
-
// not done here: the take goes to `upload`, and the
|
|
7
|
+
// not done here: the take goes to `upload`, and whoever receives it (a relay with `transcribe`, or the owner's Mac) writes the transcript. A voice note
|
|
8
8
|
// alone is a whole report, so a field with no words and one take is a complete answer.
|
|
9
9
|
//
|
|
10
10
|
// A tap starts a take that keeps recording until the next tap (or the time limit); a press held longer
|
package/dist/client/mine.js
CHANGED
|
@@ -31,6 +31,8 @@ export function MySuggestions({ adapters, onOpen }) {
|
|
|
31
31
|
const answered = useRef(false);
|
|
32
32
|
useClearOnSignOut(rt, who, adapters.words.app);
|
|
33
33
|
useEffect(() => { loads.current++; known.current = null; answered.current = false; setRows(null); setOpen(null); setBad(''); setUpdating(false); setFresh(new Set()); }, [rt]);
|
|
34
|
+
// Leaving the screen retires every load and recount still running, as a new account does: none may set state after.
|
|
35
|
+
useEffect(() => () => { loads.current++; }, []);
|
|
34
36
|
const recount = useCallback(async () => {
|
|
35
37
|
if (!rt || !known.current)
|
|
36
38
|
return;
|
package/dist/client/sheet.js
CHANGED
|
@@ -203,7 +203,7 @@ export function SuggestSheet({ adapters, where, onClose, initial }) {
|
|
|
203
203
|
await chain.current;
|
|
204
204
|
return (await saveDraft(rt.store, key, {})).reportId;
|
|
205
205
|
}, [rt, key]);
|
|
206
|
-
// A finished take: kept as a copy under this report, and listed.
|
|
206
|
+
// A finished take: kept as a copy under this report, and listed. The transcript is written where it is received.
|
|
207
207
|
const keepTake = useCallback(async (fieldId, original, blob, ms) => {
|
|
208
208
|
if (!rt || !key)
|
|
209
209
|
return { refused: S.loading };
|
package/dist/github/compose.d.ts
CHANGED
|
@@ -46,7 +46,8 @@ export interface Destination {
|
|
|
46
46
|
account: string;
|
|
47
47
|
/** False when files cannot reach this repo yet (no App installed and the filer cannot push): they wait. */
|
|
48
48
|
attaches: boolean;
|
|
49
|
-
/** False when nobody transcribes voice notes (
|
|
49
|
+
/** False when nobody transcribes voice notes (no relay `transcribe` and no Mac that writes one; a relay says which in
|
|
50
|
+
* its `capabilities`): the list does not promise a transcript. */
|
|
50
51
|
transcribes?: boolean;
|
|
51
52
|
/** The largest file this destination takes; a larger one is named in the list as staying on the phone. */
|
|
52
53
|
maxInlineBytes?: number;
|
|
@@ -104,8 +105,12 @@ export interface ComposeOptions {
|
|
|
104
105
|
filerRole?: string;
|
|
105
106
|
/** file name -> its link, from an AttachmentHost. A file with no link yet is written as still being added. */
|
|
106
107
|
attachmentUrls?: Record<string, string>;
|
|
107
|
-
/** The voice notes' transcript
|
|
108
|
+
/** The voice notes' transcript. */
|
|
108
109
|
transcript?: string;
|
|
110
|
+
/** Who made it: 'relay' when the relay transcribed it as it filed; otherwise it came with the request (the owner's Mac). */
|
|
111
|
+
transcriptBy?: 'relay' | 'mac';
|
|
112
|
+
/** A plain sentence saying a transcript, or part of one, could not be made and why; written under the voice note. */
|
|
113
|
+
transcriptNote?: string;
|
|
109
114
|
/** The first body, written before any file is saved: every attachment is "being added". */
|
|
110
115
|
pending?: boolean;
|
|
111
116
|
}
|
package/dist/github/compose.js
CHANGED
|
@@ -192,6 +192,7 @@ export function composeIssue(report, opts = {}) {
|
|
|
192
192
|
};
|
|
193
193
|
const words = scrub(text(report.words).trim());
|
|
194
194
|
const transcript = scrub(text(opts.transcript).trim());
|
|
195
|
+
const note = inline(text(opts.transcriptNote).trim());
|
|
195
196
|
// Only links the host produced, and only plain https ones, become images or links; anything else is still "being added".
|
|
196
197
|
const urls = opts.pending ? {} : Object.fromEntries(Object.entries(opts.attachmentUrls ?? {}).flatMap(([k, u]) => (safeUrl(u) ? [[k, u]] : [])));
|
|
197
198
|
const media = report.media ?? [];
|
|
@@ -217,7 +218,9 @@ export function composeIssue(report, opts = {}) {
|
|
|
217
218
|
if (has.has('words'))
|
|
218
219
|
out.push('## What they said', fence(said), '');
|
|
219
220
|
if (has.has('voice')) {
|
|
220
|
-
out.push(transcript ? "## Voice note (transcribed on the owner's Mac)" : '## Voice note', heard ? fence(heard) : 'Not transcribed.');
|
|
221
|
+
out.push(transcript ? (opts.transcriptBy === 'relay' ? '## Voice note (transcribed automatically)' : "## Voice note (transcribed on the owner's Mac)") : '## Voice note', heard ? fence(heard) : (note || 'Not transcribed.'));
|
|
222
|
+
if (heard && note)
|
|
223
|
+
out.push('', note);
|
|
221
224
|
const links = voice.filter((v) => urls[v.file]).map((v) => `[${inline(v.file)}](${urls[v.file]})`);
|
|
222
225
|
if (links.length)
|
|
223
226
|
out.push('', ...links);
|
package/dist/github/filer.d.ts
CHANGED
|
@@ -51,11 +51,14 @@ export interface RelayFiler {
|
|
|
51
51
|
}
|
|
52
52
|
/** Files larger than this go to the relay staged (one signed PUT each) rather than inside the request. */
|
|
53
53
|
export declare const STAGE_OVER_BYTES: number;
|
|
54
|
+
/** `transcribes`: the relay writes a voice note's transcript itself (a host passed `transcribe`); set the sheet's
|
|
55
|
+
* `Destination.transcribes` from it. */
|
|
54
56
|
export interface RelayCapabilities {
|
|
55
57
|
actions: string[];
|
|
56
58
|
staging: boolean;
|
|
57
59
|
inlineBytes: number;
|
|
58
60
|
maxBytes?: Record<string, number>;
|
|
61
|
+
transcribes?: boolean;
|
|
59
62
|
}
|
|
60
63
|
/** `url` is where the relay is mounted; each action is posted to `<url>/<action>`. */
|
|
61
64
|
export declare function relayFiler({ url, headers, fetch }: {
|
package/dist/github/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { fileIssue, updateIssue, addFollowUp, issueStates, issueStatus, fileSugg
|
|
|
6
6
|
export type { GitHubConfig, FilingConfig, IssueState, FileSuggestionInput, FiledSuggestion, Fetch } from './api.ts';
|
|
7
7
|
export { branchHost, relayHost, toBase64, attachmentUrl, ATTACHMENTS_BRANCH, CONTENTS_API_BYTES } from './hosts.ts';
|
|
8
8
|
export type { AttachmentHost, AttachmentTarget, AttachmentFile } from './hosts.ts';
|
|
9
|
-
export { createSuggestionRelay, createAttachRelay, memoryUsage, RELAY_LIMITS, RELAY_VOICE_BYTES, FILING_LEASE_MS } from './relay.ts';
|
|
10
|
-
export type { SuggestionRelayOptions, AttachRelayOptions, RelayLimits, RelayUsage, RelayIdentity, Reservation, FiledRecord, StagingAdapter } from './relay.ts';
|
|
9
|
+
export { createSuggestionRelay, createAttachRelay, memoryUsage, RELAY_LIMITS, RELAY_VOICE_BYTES, FILING_LEASE_MS, TRANSCRIBE_TIMEOUT_MS, TRANSCRIPT_MISSING } from './relay.ts';
|
|
10
|
+
export type { SuggestionRelayOptions, AttachRelayOptions, RelayLimits, RelayUsage, RelayIdentity, Reservation, FiledRecord, StagingAdapter, RelayVoice, RelayTranscriber } from './relay.ts';
|
|
11
11
|
export { relayFiler, canFileDirectly, STAGE_OVER_BYTES } from './filer.ts';
|
|
12
12
|
export type { RelayFiler, RelayFiling, RelayFile, RelayCapabilities } from './filer.ts';
|
package/dist/github/index.js
CHANGED
|
@@ -5,5 +5,5 @@ export { privacyCatch, redact, mayFileAsIs, normalize } from './privacy.js';
|
|
|
5
5
|
export { composeIssue, whatGoes, destinationWords, pieces, BODY_LIMIT, filedByLine, endsWithFiledBy, FILED_BY } from './compose.js';
|
|
6
6
|
export { fileIssue, updateIssue, addFollowUp, issueStates, issueStatus, fileSuggestion, attachPending, github, GitHubError } from './api.js';
|
|
7
7
|
export { branchHost, relayHost, toBase64, attachmentUrl, ATTACHMENTS_BRANCH, CONTENTS_API_BYTES } from './hosts.js';
|
|
8
|
-
export { createSuggestionRelay, createAttachRelay, memoryUsage, RELAY_LIMITS, RELAY_VOICE_BYTES, FILING_LEASE_MS } from './relay.js';
|
|
8
|
+
export { createSuggestionRelay, createAttachRelay, memoryUsage, RELAY_LIMITS, RELAY_VOICE_BYTES, FILING_LEASE_MS, TRANSCRIBE_TIMEOUT_MS, TRANSCRIPT_MISSING } from './relay.js';
|
|
9
9
|
export { relayFiler, canFileDirectly, STAGE_OVER_BYTES } from './filer.js';
|
package/dist/github/relay.d.ts
CHANGED
|
@@ -97,6 +97,28 @@ export interface RelayIdentity {
|
|
|
97
97
|
handle?: string;
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
|
+
/** One voice recording handed to the host's transcriber: its file name, its type as audio, and its bytes (read from
|
|
101
|
+
* staging already when it was staged; `staged` is then its staging key, for a host that would rather sign a read link). */
|
|
102
|
+
export interface RelayVoice {
|
|
103
|
+
name: string;
|
|
104
|
+
mimeType: string;
|
|
105
|
+
bytes: Uint8Array;
|
|
106
|
+
staged?: string;
|
|
107
|
+
}
|
|
108
|
+
/** Answers the words said in one recording. `signal` aborts when the relay stops waiting. */
|
|
109
|
+
export type RelayTranscriber = (voice: RelayVoice, o: {
|
|
110
|
+
signal: AbortSignal;
|
|
111
|
+
}) => Promise<string>;
|
|
112
|
+
/** How long the relay waits for all of a request's transcripts before it files without them. Serverless hosts cap a
|
|
113
|
+
* request (Vercel's default is 60 s), so this leaves room for GitHub. */
|
|
114
|
+
export declare const TRANSCRIBE_TIMEOUT_MS = 25000;
|
|
115
|
+
/** The plain words an issue uses for why a transcript is missing. Never the transcriber's own error, which can carry
|
|
116
|
+
* anything (a key, a URL, a provider's internals). */
|
|
117
|
+
export declare const TRANSCRIPT_MISSING: {
|
|
118
|
+
readonly timeout: 'the transcription service did not answer in time';
|
|
119
|
+
readonly failed: 'the transcription service failed or refused the recording';
|
|
120
|
+
readonly silent: 'no speech was heard in the recording';
|
|
121
|
+
};
|
|
100
122
|
export interface SuggestionRelayOptions {
|
|
101
123
|
/** The GitHub App the relay acts as: its numeric id and its private key (PEM, PKCS#1 as GitHub issues it, or PKCS#8). */
|
|
102
124
|
app: {
|
|
@@ -125,6 +147,11 @@ export interface SuggestionRelayOptions {
|
|
|
125
147
|
staging?: StagingAdapter;
|
|
126
148
|
/** May lower any limit, never raise one. */
|
|
127
149
|
limits?: Partial<RelayLimits>;
|
|
150
|
+
/** Writes the transcript of each voice note a `file` or `follow-up` brings with no `transcript`. Without it the issue
|
|
151
|
+
* says the note was not transcribed, and `capabilities` says `transcribes: false`. */
|
|
152
|
+
transcribe?: RelayTranscriber;
|
|
153
|
+
/** Default TRANSCRIBE_TIMEOUT_MS; all of a request's notes are transcribed at once inside it. */
|
|
154
|
+
transcribeTimeoutMs?: number;
|
|
128
155
|
usage?: RelayUsage;
|
|
129
156
|
fetch?: Fetch;
|
|
130
157
|
now?: () => number;
|
package/dist/github/relay.js
CHANGED
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
// - attach: for a filer who opened the issue themselves but cannot push; the relay proves they could file there by
|
|
10
10
|
// reading the issue and requiring it to carry the report.
|
|
11
11
|
//
|
|
12
|
+
// With `transcribe`, the relay also writes the transcript of each voice note a request brings without one, before the
|
|
13
|
+
// privacy catch, so the transcript is caught like the words. A transcriber that fails or is slow never stops a filing.
|
|
14
|
+
//
|
|
12
15
|
// Web-standard only: Request, Response, fetch, crypto.subtle.
|
|
13
16
|
import { CEILINGS, isRepoName, isReportId, validContact, validateReport } from '../contract.mjs';
|
|
14
17
|
import { cappedText, json } from '../server/http.js';
|
|
@@ -92,6 +95,16 @@ export function memoryUsage({ now = () => Date.now() } = {}) {
|
|
|
92
95
|
async filer(repo, num) { return issues.get(`${repo}#${num}`) ?? null; },
|
|
93
96
|
};
|
|
94
97
|
}
|
|
98
|
+
/** How long the relay waits for all of a request's transcripts before it files without them. Serverless hosts cap a
|
|
99
|
+
* request (Vercel's default is 60 s), so this leaves room for GitHub. */
|
|
100
|
+
export const TRANSCRIBE_TIMEOUT_MS = 25_000;
|
|
101
|
+
/** The plain words an issue uses for why a transcript is missing. Never the transcriber's own error, which can carry
|
|
102
|
+
* anything (a key, a URL, a provider's internals). */
|
|
103
|
+
export const TRANSCRIPT_MISSING = {
|
|
104
|
+
timeout: 'the transcription service did not answer in time',
|
|
105
|
+
failed: 'the transcription service failed or refused the recording',
|
|
106
|
+
silent: 'no speech was heard in the recording',
|
|
107
|
+
};
|
|
95
108
|
/** How long a filing holds its report before another try may take it over (its process is presumed dead). */
|
|
96
109
|
export const FILING_LEASE_MS = 5 * 60_000;
|
|
97
110
|
const FILE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
|
|
@@ -282,6 +295,32 @@ export function createSuggestionRelay(opts, only) {
|
|
|
282
295
|
return json(413, { error: `that file is larger than the ${max} bytes allowed` });
|
|
283
296
|
return { name: x.name, type: real, kind, bytes, ...(stagedKey ? { stagedKey } : {}) };
|
|
284
297
|
}
|
|
298
|
+
/** The transcript for a request's voice notes: the request's own when it carries one, else the relay's (with a plain
|
|
299
|
+
* note for any note it could not transcribe), else none. Never throws. */
|
|
300
|
+
async function transcriptFor(files, given) {
|
|
301
|
+
if (typeof given === 'string' && given.trim())
|
|
302
|
+
return { transcript: given };
|
|
303
|
+
const voices = files.filter((f) => f.kind === 'voice');
|
|
304
|
+
if (!opts.transcribe || !voices.length)
|
|
305
|
+
return {};
|
|
306
|
+
const ms = opts.transcribeTimeoutMs ?? TRANSCRIBE_TIMEOUT_MS;
|
|
307
|
+
const stop = new AbortController();
|
|
308
|
+
let timer;
|
|
309
|
+
const late = new Promise((res) => { timer = setTimeout(() => { stop.abort(); res('late'); }, ms); });
|
|
310
|
+
const one = (v) => Promise.resolve()
|
|
311
|
+
.then(() => opts.transcribe({ name: v.name, mimeType: v.type.replace(/^video\//, 'audio/'), bytes: v.bytes, ...(v.stagedKey ? { staged: v.stagedKey } : {}) }, { signal: stop.signal }))
|
|
312
|
+
.then((t) => (typeof t === 'string' && t.trim() ? { text: t.trim() } : { fail: TRANSCRIPT_MISSING.silent }), () => ({ fail: TRANSCRIPT_MISSING.failed }));
|
|
313
|
+
const got = await Promise.race([Promise.all(voices.map(one)), late]);
|
|
314
|
+
clearTimeout(timer);
|
|
315
|
+
const results = got === 'late' ? voices.map(() => ({ fail: TRANSCRIPT_MISSING.timeout })) : got;
|
|
316
|
+
const many = voices.length > 1;
|
|
317
|
+
const texts = results.flatMap((r, i) => ('text' in r ? [many ? `(${voices[i].name})\n${r.text}` : r.text] : []));
|
|
318
|
+
const fails = results.flatMap((r, i) => ('fail' in r ? [many ? `${voices[i].name}: ${r.fail}` : r.fail] : []));
|
|
319
|
+
const note = fails.length
|
|
320
|
+
? `The transcript${many ? ` of ${fails.length === voices.length ? 'the recordings' : `${fails.length} of ${voices.length} recordings`}` : ''} could not be made: ${fails.join('; ')}.${texts.length ? '' : ` The recording${many ? 's are' : ' is'} attached.`}`
|
|
321
|
+
: undefined;
|
|
322
|
+
return { ...(texts.length ? { transcript: texts.join('\n\n'), by: 'relay' } : {}), ...(note ? { note } : {}) };
|
|
323
|
+
}
|
|
285
324
|
/** The bytes a request still has to hold today: inline files only, since upload-url held a staged file's up front. */
|
|
286
325
|
const inlineBytesOf = (files) => files.reduce((n, f) => n + (f.stagedKey ? 0 : f.bytes.length), 0);
|
|
287
326
|
const discardStaged = async (files) => {
|
|
@@ -381,12 +420,14 @@ export function createSuggestionRelay(opts, only) {
|
|
|
381
420
|
if (appId !== undefined && opts.apps && (typeof appId !== 'string' || !Object.prototype.hasOwnProperty.call(opts.apps, appId)))
|
|
382
421
|
return bad('unknown app');
|
|
383
422
|
const app = opts.apps && typeof appId === 'string' ? opts.apps[appId] : undefined;
|
|
423
|
+
// The transcript is made before the catch reads anything, so it is caught like the words.
|
|
424
|
+
const heard = await transcriptFor(files, body.transcript);
|
|
384
425
|
// Who it is from comes from the host, never the request: the name, the role and the contact.
|
|
385
426
|
const contact = contactFor(me, report.who?.contact);
|
|
386
427
|
const appVersion = typeof report.diagnostics?.appVersion === 'string' ? report.diagnostics.appVersion : undefined;
|
|
387
428
|
const readable = {
|
|
388
429
|
words: report.words, followUps: report.followUps, where: report.where, diagnostics: report.diagnostics,
|
|
389
|
-
context: report.context, transcript:
|
|
430
|
+
context: report.context, transcript: heard.transcript,
|
|
390
431
|
filerName: me.name, appName: app?.name, who: { contact },
|
|
391
432
|
files: files.map((f) => ({ name: f.name })),
|
|
392
433
|
};
|
|
@@ -438,6 +479,8 @@ export function createSuggestionRelay(opts, only) {
|
|
|
438
479
|
filerName: typeof clean.filerName === 'string' && clean.filerName.trim() ? clean.filerName.trim().slice(0, 100) : 'Someone',
|
|
439
480
|
filerRole: role,
|
|
440
481
|
transcript: clean.transcript,
|
|
482
|
+
...(heard.by && clean.transcript ? { transcriptBy: heard.by } : {}),
|
|
483
|
+
...(heard.note ? { transcriptNote: heard.note } : {}),
|
|
441
484
|
attachmentUrls,
|
|
442
485
|
});
|
|
443
486
|
const made = await fileIssue({ repo, token, fetch: opts.fetch, api: opts.api }, issue);
|
|
@@ -488,7 +531,8 @@ export function createSuggestionRelay(opts, only) {
|
|
|
488
531
|
if (checked instanceof Response)
|
|
489
532
|
return checked;
|
|
490
533
|
const files = checked;
|
|
491
|
-
const
|
|
534
|
+
const heard = await transcriptFor(files, body.transcript);
|
|
535
|
+
const readable = { words: typeof body.words === 'string' ? body.words.slice(0, 20_000) : '', transcript: heard.transcript, files: files.map((f) => ({ name: f.name })) };
|
|
492
536
|
const caught = catchIt(readable, account, body.redacted === true);
|
|
493
537
|
if ('res' in caught)
|
|
494
538
|
return caught.res;
|
|
@@ -500,7 +544,7 @@ export function createSuggestionRelay(opts, only) {
|
|
|
500
544
|
const links = files.map((f) => { const url = attachmentUrl(repo, ATTACHMENTS_BRANCH, `${folder}/${f.name}`); return f.kind === 'image' ? `` : `[${f.name}](${url})`; });
|
|
501
545
|
// A follow-up is the person's own words, so it sits in a fence like the words of the report.
|
|
502
546
|
const fenced = (s) => { const run = Math.max(0, ...[...s.matchAll(/`+/g)].map((m) => m[0].length)); const f = '`'.repeat(Math.max(3, run + 1)); return `${f}\n${s}\n${f}`; };
|
|
503
|
-
const text = ['## Added later', words.trim() ? fenced(words.trim()) : '', transcript ? `\n### Voice note\n${fenced(transcript.trim())}` : '', links.length ? `\n${links.join('\n')}` : ''].filter(Boolean).join('\n');
|
|
547
|
+
const text = ['## Added later', words.trim() ? fenced(words.trim()) : '', transcript ? `\n### Voice note\n${fenced(transcript.trim())}` : '', heard.note ? `\n${heard.note}` : '', links.length ? `\n${links.join('\n')}` : ''].filter(Boolean).join('\n');
|
|
504
548
|
if (text.length > BODY_LIMIT)
|
|
505
549
|
return json(413, { error: `that follow-up is longer than GitHub takes in a comment (${BODY_LIMIT} characters)` });
|
|
506
550
|
const held = await reserve(account, reportId, inlineBytesOf(files));
|
|
@@ -707,6 +751,7 @@ export function createSuggestionRelay(opts, only) {
|
|
|
707
751
|
const capabilities = () => json(200, {
|
|
708
752
|
actions: ACTIONS.filter((a) => (only ? a === only : a !== 'upload-url' || Boolean(opts.staging))),
|
|
709
753
|
staging: Boolean(opts.staging),
|
|
754
|
+
transcribes: Boolean(opts.transcribe),
|
|
710
755
|
inlineBytes: limits.inlineBytes,
|
|
711
756
|
maxBytes: { image: limits.imageBytes, video: limits.videoBytes, voice: limits.voiceBytes },
|
|
712
757
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supersuit/suggest-a-change",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The report format and flow behind a Suggest a change button: what a report is, who acts at each step, the screens, and the check every app runs. The contract has zero dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/client/adapters.ts
CHANGED
|
@@ -33,7 +33,7 @@ export interface FieldProps {
|
|
|
33
33
|
placeholder?: string
|
|
34
34
|
multiline?: boolean
|
|
35
35
|
type?: 'text' | 'search'
|
|
36
|
-
/** Gets each finished take. The sheet keeps the recording;
|
|
36
|
+
/** Gets each finished take. The sheet keeps the recording; the transcript is written where it is received (a relay with `transcribe`, or the owner's Mac). */
|
|
37
37
|
upload?: HeardUpload
|
|
38
38
|
onHeard?(h: { audio: string; text: string }): void
|
|
39
39
|
onKept?(t: { key: string; ms: number }): void
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// INSIDE the box (bottom right; centred at the right of a one-line input), in one [data-voice-field]
|
|
4
4
|
// container with nothing else typeable in it. A take is
|
|
5
5
|
// recorded with the module's recorder (written to the phone's database as it is made). Transcription is
|
|
6
|
-
// not done here: the take goes to `upload`, and the
|
|
6
|
+
// not done here: the take goes to `upload`, and whoever receives it (a relay with `transcribe`, or the owner's Mac) writes the transcript. A voice note
|
|
7
7
|
// alone is a whole report, so a field with no words and one take is a complete answer.
|
|
8
8
|
//
|
|
9
9
|
// A tap starts a take that keeps recording until the next tap (or the time limit); a press held longer
|
package/src/client/mine.tsx
CHANGED
|
@@ -36,6 +36,8 @@ export function MySuggestions({ adapters, onOpen }: { adapters: Adapters; onOpen
|
|
|
36
36
|
const answered = useRef(false)
|
|
37
37
|
useClearOnSignOut(rt, who, adapters.words.app)
|
|
38
38
|
useEffect(() => { loads.current++; known.current = null; answered.current = false; setRows(null); setOpen(null); setBad(''); setUpdating(false); setFresh(new Set()) }, [rt])
|
|
39
|
+
// Leaving the screen retires every load and recount still running, as a new account does: none may set state after.
|
|
40
|
+
useEffect(() => () => { loads.current++ }, [])
|
|
39
41
|
|
|
40
42
|
const recount = useCallback(async () => {
|
|
41
43
|
if (!rt || !known.current) return
|
package/src/client/sheet.tsx
CHANGED
|
@@ -198,7 +198,7 @@ export function SuggestSheet({ adapters, where, onClose, initial }: { adapters:
|
|
|
198
198
|
return (await saveDraft(rt!.store, key!, {})).reportId
|
|
199
199
|
}, [rt, key])
|
|
200
200
|
|
|
201
|
-
// A finished take: kept as a copy under this report, and listed.
|
|
201
|
+
// A finished take: kept as a copy under this report, and listed. The transcript is written where it is received.
|
|
202
202
|
const keepTake = useCallback(async (fieldId: string, original: string, blob: Blob, ms: number) => {
|
|
203
203
|
if (!rt || !key) return { refused: S.loading }
|
|
204
204
|
if (ms > ceilings.voiceMs) return { refused: S.voiceTooLong }
|
package/src/github/compose.ts
CHANGED
|
@@ -24,7 +24,8 @@ export interface Destination {
|
|
|
24
24
|
account: string
|
|
25
25
|
/** False when files cannot reach this repo yet (no App installed and the filer cannot push): they wait. */
|
|
26
26
|
attaches: boolean
|
|
27
|
-
/** False when nobody transcribes voice notes (
|
|
27
|
+
/** False when nobody transcribes voice notes (no relay `transcribe` and no Mac that writes one; a relay says which in
|
|
28
|
+
* its `capabilities`): the list does not promise a transcript. */
|
|
28
29
|
transcribes?: boolean
|
|
29
30
|
/** The largest file this destination takes; a larger one is named in the list as staying on the phone. */
|
|
30
31
|
maxInlineBytes?: number
|
|
@@ -61,8 +62,12 @@ export interface ComposeOptions {
|
|
|
61
62
|
filerRole?: string
|
|
62
63
|
/** file name -> its link, from an AttachmentHost. A file with no link yet is written as still being added. */
|
|
63
64
|
attachmentUrls?: Record<string, string>
|
|
64
|
-
/** The voice notes' transcript
|
|
65
|
+
/** The voice notes' transcript. */
|
|
65
66
|
transcript?: string
|
|
67
|
+
/** Who made it: 'relay' when the relay transcribed it as it filed; otherwise it came with the request (the owner's Mac). */
|
|
68
|
+
transcriptBy?: 'relay' | 'mac'
|
|
69
|
+
/** A plain sentence saying a transcript, or part of one, could not be made and why; written under the voice note. */
|
|
70
|
+
transcriptNote?: string
|
|
66
71
|
/** The first body, written before any file is saved: every attachment is "being added". */
|
|
67
72
|
pending?: boolean
|
|
68
73
|
}
|
|
@@ -247,6 +252,7 @@ export function composeIssue(report: Draft, opts: ComposeOptions = {}): Composed
|
|
|
247
252
|
}
|
|
248
253
|
const words = scrub(text(report.words).trim())
|
|
249
254
|
const transcript = scrub(text(opts.transcript).trim())
|
|
255
|
+
const note = inline(text(opts.transcriptNote).trim())
|
|
250
256
|
// Only links the host produced, and only plain https ones, become images or links; anything else is still "being added".
|
|
251
257
|
const urls: Record<string, string> = opts.pending ? {} : Object.fromEntries(Object.entries(opts.attachmentUrls ?? {}).flatMap(([k, u]) => (safeUrl(u) ? [[k, u]] : [])))
|
|
252
258
|
const media = report.media ?? []
|
|
@@ -274,7 +280,8 @@ export function composeIssue(report: Draft, opts: ComposeOptions = {}): Composed
|
|
|
274
280
|
const out: string[] = []
|
|
275
281
|
if (has.has('words')) out.push('## What they said', fence(said), '')
|
|
276
282
|
if (has.has('voice')) {
|
|
277
|
-
out.push(transcript ? "## Voice note (transcribed on the owner's Mac)" : '## Voice note', heard ? fence(heard) : 'Not transcribed.')
|
|
283
|
+
out.push(transcript ? (opts.transcriptBy === 'relay' ? '## Voice note (transcribed automatically)' : "## Voice note (transcribed on the owner's Mac)") : '## Voice note', heard ? fence(heard) : (note || 'Not transcribed.'))
|
|
284
|
+
if (heard && note) out.push('', note)
|
|
278
285
|
const links = voice.filter((v) => urls[v.file]).map((v) => `[${inline(v.file)}](${urls[v.file]})`)
|
|
279
286
|
if (links.length) out.push('', ...links)
|
|
280
287
|
if (coming && !has.has('images') && !has.has('video')) out.push('', coming)
|
package/src/github/filer.ts
CHANGED
|
@@ -38,7 +38,9 @@ const raw = (b: RelayFile['bytes']): Uint8Array => {
|
|
|
38
38
|
if (b instanceof ArrayBuffer) return new Uint8Array(b)
|
|
39
39
|
const bin = atob(b); const out = new Uint8Array(bin.length); for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i); return out
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
/** `transcribes`: the relay writes a voice note's transcript itself (a host passed `transcribe`); set the sheet's
|
|
42
|
+
* `Destination.transcribes` from it. */
|
|
43
|
+
export interface RelayCapabilities { actions: string[]; staging: boolean; inlineBytes: number; maxBytes?: Record<string, number>; transcribes?: boolean }
|
|
42
44
|
|
|
43
45
|
/** `url` is where the relay is mounted; each action is posted to `<url>/<action>`. */
|
|
44
46
|
export function relayFiler({ url, headers = {}, fetch }: { url: string; headers?: Record<string, string>; fetch?: Fetch }): RelayFiler {
|
package/src/github/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { fileIssue, updateIssue, addFollowUp, issueStates, issueStatus, fileSugg
|
|
|
9
9
|
export type { GitHubConfig, FilingConfig, IssueState, FileSuggestionInput, FiledSuggestion, Fetch } from './api.ts'
|
|
10
10
|
export { branchHost, relayHost, toBase64, attachmentUrl, ATTACHMENTS_BRANCH, CONTENTS_API_BYTES } from './hosts.ts'
|
|
11
11
|
export type { AttachmentHost, AttachmentTarget, AttachmentFile } from './hosts.ts'
|
|
12
|
-
export { createSuggestionRelay, createAttachRelay, memoryUsage, RELAY_LIMITS, RELAY_VOICE_BYTES, FILING_LEASE_MS } from './relay.ts'
|
|
13
|
-
export type { SuggestionRelayOptions, AttachRelayOptions, RelayLimits, RelayUsage, RelayIdentity, Reservation, FiledRecord, StagingAdapter } from './relay.ts'
|
|
12
|
+
export { createSuggestionRelay, createAttachRelay, memoryUsage, RELAY_LIMITS, RELAY_VOICE_BYTES, FILING_LEASE_MS, TRANSCRIBE_TIMEOUT_MS, TRANSCRIPT_MISSING } from './relay.ts'
|
|
13
|
+
export type { SuggestionRelayOptions, AttachRelayOptions, RelayLimits, RelayUsage, RelayIdentity, Reservation, FiledRecord, StagingAdapter, RelayVoice, RelayTranscriber } from './relay.ts'
|
|
14
14
|
export { relayFiler, canFileDirectly, STAGE_OVER_BYTES } from './filer.ts'
|
|
15
15
|
export type { RelayFiler, RelayFiling, RelayFile, RelayCapabilities } from './filer.ts'
|
package/src/github/relay.ts
CHANGED
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
// - attach: for a filer who opened the issue themselves but cannot push; the relay proves they could file there by
|
|
10
10
|
// reading the issue and requiring it to carry the report.
|
|
11
11
|
//
|
|
12
|
+
// With `transcribe`, the relay also writes the transcript of each voice note a request brings without one, before the
|
|
13
|
+
// privacy catch, so the transcript is caught like the words. A transcriber that fails or is slow never stops a filing.
|
|
14
|
+
//
|
|
12
15
|
// Web-standard only: Request, Response, fetch, crypto.subtle.
|
|
13
16
|
import { CEILINGS, isRepoName, isReportId, validContact, validateReport } from '../contract.mjs'
|
|
14
17
|
import { cappedText, json } from '../server/http.ts'
|
|
@@ -145,6 +148,22 @@ export interface RelayIdentity {
|
|
|
145
148
|
contact?: { email?: string; phone?: string; handle?: string }
|
|
146
149
|
}
|
|
147
150
|
|
|
151
|
+
/** One voice recording handed to the host's transcriber: its file name, its type as audio, and its bytes (read from
|
|
152
|
+
* staging already when it was staged; `staged` is then its staging key, for a host that would rather sign a read link). */
|
|
153
|
+
export interface RelayVoice { name: string; mimeType: string; bytes: Uint8Array; staged?: string }
|
|
154
|
+
/** Answers the words said in one recording. `signal` aborts when the relay stops waiting. */
|
|
155
|
+
export type RelayTranscriber = (voice: RelayVoice, o: { signal: AbortSignal }) => Promise<string>
|
|
156
|
+
/** How long the relay waits for all of a request's transcripts before it files without them. Serverless hosts cap a
|
|
157
|
+
* request (Vercel's default is 60 s), so this leaves room for GitHub. */
|
|
158
|
+
export const TRANSCRIBE_TIMEOUT_MS = 25_000
|
|
159
|
+
/** The plain words an issue uses for why a transcript is missing. Never the transcriber's own error, which can carry
|
|
160
|
+
* anything (a key, a URL, a provider's internals). */
|
|
161
|
+
export const TRANSCRIPT_MISSING = {
|
|
162
|
+
timeout: 'the transcription service did not answer in time',
|
|
163
|
+
failed: 'the transcription service failed or refused the recording',
|
|
164
|
+
silent: 'no speech was heard in the recording',
|
|
165
|
+
} as const
|
|
166
|
+
|
|
148
167
|
export interface SuggestionRelayOptions {
|
|
149
168
|
/** The GitHub App the relay acts as: its numeric id and its private key (PEM, PKCS#1 as GitHub issues it, or PKCS#8). */
|
|
150
169
|
app: { id: number | string; privateKey: string }
|
|
@@ -164,6 +183,11 @@ export interface SuggestionRelayOptions {
|
|
|
164
183
|
staging?: StagingAdapter
|
|
165
184
|
/** May lower any limit, never raise one. */
|
|
166
185
|
limits?: Partial<RelayLimits>
|
|
186
|
+
/** Writes the transcript of each voice note a `file` or `follow-up` brings with no `transcript`. Without it the issue
|
|
187
|
+
* says the note was not transcribed, and `capabilities` says `transcribes: false`. */
|
|
188
|
+
transcribe?: RelayTranscriber
|
|
189
|
+
/** Default TRANSCRIBE_TIMEOUT_MS; all of a request's notes are transcribed at once inside it. */
|
|
190
|
+
transcribeTimeoutMs?: number
|
|
167
191
|
usage?: RelayUsage
|
|
168
192
|
fetch?: Fetch
|
|
169
193
|
now?: () => number
|
|
@@ -335,6 +359,30 @@ export function createSuggestionRelay(opts: SuggestionRelayOptions, only?: Actio
|
|
|
335
359
|
if (bytes.length > max) return json(413, { error: `that file is larger than the ${max} bytes allowed` })
|
|
336
360
|
return { name: x.name, type: real, kind, bytes, ...(stagedKey ? { stagedKey } : {}) }
|
|
337
361
|
}
|
|
362
|
+
/** The transcript for a request's voice notes: the request's own when it carries one, else the relay's (with a plain
|
|
363
|
+
* note for any note it could not transcribe), else none. Never throws. */
|
|
364
|
+
async function transcriptFor(files: Checked[], given: unknown): Promise<{ transcript?: string; by?: 'relay'; note?: string }> {
|
|
365
|
+
if (typeof given === 'string' && given.trim()) return { transcript: given }
|
|
366
|
+
const voices = files.filter((f) => f.kind === 'voice')
|
|
367
|
+
if (!opts.transcribe || !voices.length) return {}
|
|
368
|
+
const ms = opts.transcribeTimeoutMs ?? TRANSCRIBE_TIMEOUT_MS
|
|
369
|
+
const stop = new AbortController()
|
|
370
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
371
|
+
const late = new Promise<'late'>((res) => { timer = setTimeout(() => { stop.abort(); res('late') }, ms) })
|
|
372
|
+
const one = (v: Checked) => Promise.resolve()
|
|
373
|
+
.then(() => opts.transcribe!({ name: v.name, mimeType: v.type.replace(/^video\//, 'audio/'), bytes: v.bytes, ...(v.stagedKey ? { staged: v.stagedKey } : {}) }, { signal: stop.signal }))
|
|
374
|
+
.then((t) => (typeof t === 'string' && t.trim() ? { text: t.trim() } : { fail: TRANSCRIPT_MISSING.silent }), () => ({ fail: TRANSCRIPT_MISSING.failed }))
|
|
375
|
+
const got = await Promise.race([Promise.all(voices.map(one)), late])
|
|
376
|
+
clearTimeout(timer)
|
|
377
|
+
const results: ({ text: string } | { fail: string })[] = got === 'late' ? voices.map(() => ({ fail: TRANSCRIPT_MISSING.timeout })) : got
|
|
378
|
+
const many = voices.length > 1
|
|
379
|
+
const texts = results.flatMap((r, i) => ('text' in r ? [many ? `(${voices[i].name})\n${r.text}` : r.text] : []))
|
|
380
|
+
const fails = results.flatMap((r, i) => ('fail' in r ? [many ? `${voices[i].name}: ${r.fail}` : r.fail] : []))
|
|
381
|
+
const note = fails.length
|
|
382
|
+
? `The transcript${many ? ` of ${fails.length === voices.length ? 'the recordings' : `${fails.length} of ${voices.length} recordings`}` : ''} could not be made: ${fails.join('; ')}.${texts.length ? '' : ` The recording${many ? 's are' : ' is'} attached.`}`
|
|
383
|
+
: undefined
|
|
384
|
+
return { ...(texts.length ? { transcript: texts.join('\n\n'), by: 'relay' as const } : {}), ...(note ? { note } : {}) }
|
|
385
|
+
}
|
|
338
386
|
/** The bytes a request still has to hold today: inline files only, since upload-url held a staged file's up front. */
|
|
339
387
|
const inlineBytesOf = (files: Checked[]) => files.reduce((n, f) => n + (f.stagedKey ? 0 : f.bytes.length), 0)
|
|
340
388
|
const discardStaged = async (files: Checked[]) => {
|
|
@@ -409,12 +457,14 @@ export function createSuggestionRelay(opts: SuggestionRelayOptions, only?: Actio
|
|
|
409
457
|
const appId = body.app
|
|
410
458
|
if (appId !== undefined && opts.apps && (typeof appId !== 'string' || !Object.prototype.hasOwnProperty.call(opts.apps, appId))) return bad('unknown app')
|
|
411
459
|
const app = opts.apps && typeof appId === 'string' ? opts.apps[appId] : undefined
|
|
460
|
+
// The transcript is made before the catch reads anything, so it is caught like the words.
|
|
461
|
+
const heard = await transcriptFor(files, body.transcript)
|
|
412
462
|
// Who it is from comes from the host, never the request: the name, the role and the contact.
|
|
413
463
|
const contact = contactFor(me, (report.who as { contact?: unknown } | undefined)?.contact)
|
|
414
464
|
const appVersion = typeof (report.diagnostics as { appVersion?: unknown } | undefined)?.appVersion === 'string' ? (report.diagnostics as { appVersion: string }).appVersion : undefined
|
|
415
465
|
const readable = {
|
|
416
466
|
words: report.words, followUps: report.followUps, where: report.where, diagnostics: report.diagnostics,
|
|
417
|
-
context: report.context, transcript:
|
|
467
|
+
context: report.context, transcript: heard.transcript,
|
|
418
468
|
filerName: me.name, appName: app?.name, who: { contact },
|
|
419
469
|
files: files.map((f) => ({ name: f.name })),
|
|
420
470
|
}
|
|
@@ -450,6 +500,8 @@ export function createSuggestionRelay(opts: SuggestionRelayOptions, only?: Actio
|
|
|
450
500
|
filerName: typeof clean.filerName === 'string' && clean.filerName.trim() ? clean.filerName.trim().slice(0, 100) : 'Someone',
|
|
451
501
|
filerRole: role,
|
|
452
502
|
transcript: clean.transcript,
|
|
503
|
+
...(heard.by && clean.transcript ? { transcriptBy: heard.by } : {}),
|
|
504
|
+
...(heard.note ? { transcriptNote: heard.note } : {}),
|
|
453
505
|
attachmentUrls,
|
|
454
506
|
})
|
|
455
507
|
const made = await fileIssue({ repo, token, fetch: opts.fetch, api: opts.api }, issue)
|
|
@@ -477,7 +529,8 @@ export function createSuggestionRelay(opts: SuggestionRelayOptions, only?: Actio
|
|
|
477
529
|
const checked = await checkMany(Array.isArray(body.files) ? body.files : [], () => undefined, account, reportId)
|
|
478
530
|
if (checked instanceof Response) return checked
|
|
479
531
|
const files = checked
|
|
480
|
-
const
|
|
532
|
+
const heard = await transcriptFor(files, body.transcript)
|
|
533
|
+
const readable = { words: typeof body.words === 'string' ? body.words.slice(0, 20_000) : '', transcript: heard.transcript, files: files.map((f) => ({ name: f.name })) }
|
|
481
534
|
const caught = catchIt(readable, account, body.redacted === true); if ('res' in caught) return caught.res
|
|
482
535
|
const { words, transcript } = caught.clean
|
|
483
536
|
if (!words.trim() && !transcript && !files.length) return bad('a follow-up needs words or a file')
|
|
@@ -486,7 +539,7 @@ export function createSuggestionRelay(opts: SuggestionRelayOptions, only?: Actio
|
|
|
486
539
|
const links = files.map((f) => { const url = attachmentUrl(repo, ATTACHMENTS_BRANCH, `${folder}/${f.name}`); return f.kind === 'image' ? `` : `[${f.name}](${url})` })
|
|
487
540
|
// A follow-up is the person's own words, so it sits in a fence like the words of the report.
|
|
488
541
|
const fenced = (s: string) => { const run = Math.max(0, ...[...s.matchAll(/`+/g)].map((m) => m[0].length)); const f = '`'.repeat(Math.max(3, run + 1)); return `${f}\n${s}\n${f}` }
|
|
489
|
-
const text = ['## Added later', words.trim() ? fenced(words.trim()) : '', transcript ? `\n### Voice note\n${fenced(transcript.trim())}` : '', links.length ? `\n${links.join('\n')}` : ''].filter(Boolean).join('\n')
|
|
542
|
+
const text = ['## Added later', words.trim() ? fenced(words.trim()) : '', transcript ? `\n### Voice note\n${fenced(transcript.trim())}` : '', heard.note ? `\n${heard.note}` : '', links.length ? `\n${links.join('\n')}` : ''].filter(Boolean).join('\n')
|
|
490
543
|
if (text.length > BODY_LIMIT) return json(413, { error: `that follow-up is longer than GitHub takes in a comment (${BODY_LIMIT} characters)` })
|
|
491
544
|
const held = await reserve(account, reportId, inlineBytesOf(files))
|
|
492
545
|
if (held instanceof Response) return held
|
|
@@ -613,6 +666,7 @@ export function createSuggestionRelay(opts: SuggestionRelayOptions, only?: Actio
|
|
|
613
666
|
const capabilities = () => json(200, {
|
|
614
667
|
actions: ACTIONS.filter((a) => (only ? a === only : a !== 'upload-url' || Boolean(opts.staging))),
|
|
615
668
|
staging: Boolean(opts.staging),
|
|
669
|
+
transcribes: Boolean(opts.transcribe),
|
|
616
670
|
inlineBytes: limits.inlineBytes,
|
|
617
671
|
maxBytes: { image: limits.imageBytes, video: limits.videoBytes, voice: limits.voiceBytes },
|
|
618
672
|
})
|