1- import { release as osRelease , type as osType } from 'node:os' ;
21import { join , relative } from 'node:path' ;
32
43import type {
@@ -19,65 +18,20 @@ import {
1918 buildCostReportLines ,
2019 buildUsageReportLines ,
2120 UsagePanelComponent ,
22- type ManagedUsageReport ,
2321} from '../components/messages/usage-panel' ;
2422import {
2523 FEEDBACK_ISSUE_URL ,
26- FEEDBACK_STATUS_CANCELLED ,
27- FEEDBACK_STATUS_FALLBACK ,
28- FEEDBACK_STATUS_NOT_SIGNED_IN ,
29- FEEDBACK_STATUS_SUBMITTING ,
30- FEEDBACK_STATUS_SUCCESS ,
31- FEEDBACK_TELEMETRY_EVENT ,
32- feedbackSessionLine ,
33- withFeedbackVersionPrefix ,
3424} from '../constant/feedback' ;
35- import { isManagedUsageProvider } from '../constant/pythinker-tui' ;
3625import { formatErrorMessage } from '../utils/event-payload' ;
37- import { promptFeedbackInput } from './prompts' ;
3826import type { SlashCommandHost } from './dispatch' ;
3927
4028// ---------------------------------------------------------------------------
4129// Feedback
4230// ---------------------------------------------------------------------------
4331
4432export async function handleFeedbackCommand ( host : SlashCommandHost ) : Promise < void > {
45- const fallback = ( reason : string ) : void => {
46- host . showStatus ( reason ) ;
47- host . showStatus ( FEEDBACK_ISSUE_URL ) ;
48- openUrl ( FEEDBACK_ISSUE_URL ) ;
49- } ;
50-
51- const providerKey = host . state . appState . availableModels [ host . state . appState . model ] ?. provider ;
52- if ( ! isManagedUsageProvider ( providerKey ) ) {
53- fallback ( FEEDBACK_STATUS_NOT_SIGNED_IN ) ;
54- return ;
55- }
56-
57- const content = await promptFeedbackInput ( host ) ;
58- if ( content === undefined ) {
59- host . showStatus ( FEEDBACK_STATUS_CANCELLED ) ;
60- return ;
61- }
62-
63- const spinner = host . showLoginProgressSpinner ( FEEDBACK_STATUS_SUBMITTING ) ;
64- const res = await host . harness . auth . submitFeedback ( {
65- content,
66- sessionId : host . state . appState . sessionId ,
67- version : withFeedbackVersionPrefix ( host . state . appState . version ) ,
68- os : `${ osType ( ) } ${ osRelease ( ) } ` ,
69- model : host . state . appState . model . length > 0 ? host . state . appState . model : null ,
70- } ) ;
71-
72- if ( res . kind === 'ok' ) {
73- spinner . stop ( { ok : true , label : FEEDBACK_STATUS_SUCCESS } ) ;
74- host . showStatus ( feedbackSessionLine ( host . state . appState . sessionId ) ) ;
75- host . track ( FEEDBACK_TELEMETRY_EVENT ) ;
76- return ;
77- }
78-
79- spinner . stop ( { ok : false , label : res . message } ) ;
80- fallback ( FEEDBACK_STATUS_FALLBACK ) ;
33+ host . showStatus ( FEEDBACK_ISSUE_URL ) ;
34+ openUrl ( FEEDBACK_ISSUE_URL ) ;
8135}
8236
8337// ---------------------------------------------------------------------------
@@ -94,10 +48,6 @@ interface RuntimeStatusResult {
9448 readonly error ?: string ;
9549}
9650
97- interface ManagedUsageResult {
98- readonly usage ?: ManagedUsageReport ;
99- readonly error ?: string ;
100- }
10151
10252export function showCost ( host : SlashCommandHost ) : void {
10353 const { model, modelCostRates, totalCostUsd } = host . state . appState ;
@@ -112,15 +62,12 @@ export function showCost(host: SlashCommandHost): void {
11262
11363export async function showUsage ( host : SlashCommandHost ) : Promise < void > {
11464 const sessionUsage = await loadSessionUsageReport ( host ) ;
115- const managedUsage = await loadManagedUsageReport ( host ) ;
11665 const reportArgs = {
11766 sessionUsage : sessionUsage . usage ,
11867 sessionUsageError : sessionUsage . error ,
11968 contextUsage : host . state . appState . contextUsage ,
12069 contextTokens : host . state . appState . contextTokens ,
12170 maxContextTokens : host . state . appState . maxContextTokens ,
122- managedUsage : managedUsage ?. usage ,
123- managedUsageError : managedUsage ?. error ,
12471 } ;
12572 const panel = new UsagePanelComponent ( ( ) => buildUsageReportLines ( reportArgs ) , 'primary' ) ;
12673 host . state . transcriptContainer . addChild ( panel ) ;
@@ -171,10 +118,7 @@ export async function showContextReport(
171118}
172119
173120export async function showStatusReport ( host : SlashCommandHost ) : Promise < void > {
174- const [ runtimeStatus , managedUsage ] = await Promise . all ( [
175- loadRuntimeStatusReport ( host ) ,
176- loadManagedUsageReport ( host ) ,
177- ] ) ;
121+ const runtimeStatus = await loadRuntimeStatusReport ( host ) ;
178122 const appState = host . state . appState ;
179123 const reportArgs = {
180124 version : appState . version ,
@@ -193,8 +137,6 @@ export async function showStatusReport(host: SlashCommandHost): Promise<void> {
193137 availableModels : appState . availableModels ,
194138 status : runtimeStatus . status ,
195139 statusError : runtimeStatus . error ,
196- managedUsage : managedUsage ?. usage ,
197- managedUsageError : managedUsage ?. error ,
198140 } ;
199141 const panel = new UsagePanelComponent ( ( ) => buildStatusReportLines ( reportArgs ) , 'primary' , ' Status ' ) ;
200142 host . state . transcriptContainer . addChild ( panel ) ;
@@ -456,19 +398,3 @@ async function loadRuntimeStatusReport(host: SlashCommandHost): Promise<RuntimeS
456398 }
457399}
458400
459- async function loadManagedUsageReport ( host : SlashCommandHost ) : Promise < ManagedUsageResult | undefined > {
460- const alias = host . state . appState . model ;
461- const providerKey = host . state . appState . availableModels [ alias ] ?. provider ;
462- if ( ! isManagedUsageProvider ( providerKey ) ) return undefined ;
463-
464- let res ;
465- try {
466- res = await host . harness . auth . getManagedUsage ( providerKey ) ;
467- } catch ( error ) {
468- return { error : formatErrorMessage ( error ) } ;
469- }
470- if ( res . kind === 'error' ) {
471- return { error : res . message } ;
472- }
473- return { usage : { summary : res . summary , limits : res . limits } } ;
474- }
0 commit comments