(host: SlashCommandHost)
| 31 | // --------------------------------------------------------------------------- |
| 32 | |
| 33 | export async function handleFeedbackCommand(host: SlashCommandHost): Promise<void> { |
| 34 | const fallback = (reason: string): void => { |
| 35 | host.showStatus(reason); |
| 36 | host.showStatus(FEEDBACK_ISSUE_URL); |
| 37 | openUrl(FEEDBACK_ISSUE_URL); |
| 38 | }; |
| 39 | |
| 40 | const providerKey = host.state.appState.availableModels[host.state.appState.model]?.provider; |
| 41 | if (!isManagedUsageProvider(providerKey)) { |
| 42 | fallback(FEEDBACK_STATUS_NOT_SIGNED_IN); |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | // Stage 1: collect the free-form feedback text. |
| 47 | const input = await promptFeedbackInput(host); |
| 48 | if (input === undefined) { |
| 49 | host.showStatus(FEEDBACK_STATUS_CANCELLED); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | // Stage 2: ask whether to attach diagnostics (logs / codebase). |
| 54 | const level = await promptFeedbackAttachment(host); |
| 55 | if (level === undefined) { |
| 56 | host.showStatus(FEEDBACK_STATUS_CANCELLED); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | const version = withFeedbackVersionPrefix(host.state.appState.version); |
| 61 | const spinner = host.showLoginProgressSpinner(FEEDBACK_STATUS_SUBMITTING); |
| 62 | // Guarantee the spinner's underlying setInterval is always cleared, even when |
| 63 | // submitFeedback or submitFeedbackWithAttachments throws — otherwise the |
| 64 | // interval (and its per-frame requestRender) leaks for the rest of the session. |
| 65 | let stopped = false; |
| 66 | const stopSpinner = (opts: { ok: boolean; label: string }): void => { |
| 67 | if (stopped) return; |
| 68 | stopped = true; |
| 69 | spinner.stop(opts); |
| 70 | }; |
| 71 | try { |
| 72 | const res = await host.harness.auth.submitFeedback({ |
| 73 | content: input.value, |
| 74 | sessionId: host.state.appState.sessionId, |
| 75 | version, |
| 76 | os: `${osType()} ${osRelease()}`, |
| 77 | model: host.state.appState.model.length > 0 ? host.state.appState.model : null, |
| 78 | }); |
| 79 | |
| 80 | if (res.kind !== 'ok') { |
| 81 | stopSpinner({ ok: false, label: res.message }); |
| 82 | fallback(FEEDBACK_STATUS_FALLBACK); |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | // Stage 3: prepare and upload each requested attachment independently. |
| 87 | const attachmentFailed = await submitFeedbackWithAttachments(host, res.feedbackId, level); |
| 88 | |
| 89 | stopSpinner({ ok: true, label: FEEDBACK_STATUS_SUCCESS }); |
| 90 | host.showStatus(feedbackSessionLine(host.state.appState.sessionId)); |
no test coverage detected