88 getSurveyPopupConfig ,
99 peekSurveyPopupConfig ,
1010 peekSurveyPopupConfigFresh ,
11+ resolveSurveyPopupConfig ,
1112 type SurveyPopupConfig ,
13+ type SurveyPopupPayload ,
1214} from '#/utils/survey-popup-config' ;
1315import { readSurveyLastShownTime , writeSurveyLastShownTime } from '#/utils/survey-state-store' ;
1416import { currentKimiRegion } from '#/utils/region' ;
@@ -94,7 +96,7 @@ function joinModels(models: ReadonlySet<string>): string | undefined {
9496}
9597
9698export interface SurveyControllerDeps {
97- readonly config ?: ( ) => SurveyPopupConfig ;
99+ readonly config ?: ( ) => SurveyPopupPayload ;
98100 readonly monotonicNow ?: ( ) => number ;
99101 readonly wallNow ?: ( ) => number ;
100102 readonly random ?: ( ) => number ;
@@ -145,7 +147,8 @@ export class SurveyController {
145147 private userTurnsAtLastShown : number | undefined ;
146148 private appearanceCount = 0 ;
147149 private globalLastShownAt : number | undefined ;
148- private longContextRollConsumed = false ;
150+ private readonly longContextRollConsumedModels = new Set < string | undefined > ( ) ;
151+ private longContextShownThisMount = false ;
149152 private generation = 0 ;
150153 private idleSince : number | undefined ;
151154 private openedAt = 0 ;
@@ -196,7 +199,8 @@ export class SurveyController {
196199 this . lastShownAt = undefined ;
197200 this . userTurnsAtLastShown = undefined ;
198201 this . appearanceCount = 0 ;
199- this . longContextRollConsumed = false ;
202+ this . longContextRollConsumedModels . clear ( ) ;
203+ this . longContextShownThisMount = false ;
200204 this . idleSince = undefined ;
201205 this . stickySample = undefined ;
202206 this . toolCallCount = 0 ;
@@ -444,6 +448,13 @@ export class SurveyController {
444448 return false ;
445449 }
446450
451+ private currentConfig ( ) : SurveyPopupConfig {
452+ return resolveSurveyPopupConfig (
453+ ( this . deps . config ?? defaultDeps . config ) ( ) ,
454+ resolveKfcModelId ( this . host . state . appState ) ,
455+ ) ;
456+ }
457+
447458 private evaluate ( ) : void {
448459 if ( this . machine . phase !== 'closed' ) return ;
449460 if ( ! this . configReady ) return ;
@@ -463,9 +474,12 @@ export class SurveyController {
463474 ) {
464475 return ;
465476 }
466- const config = ( this . deps . config ?? defaultDeps . config ) ( ) ;
467- const verdict = evaluateSurveyGate ( { ...this . gateInputs ( ) , config } ) ;
468- if ( verdict . longContextRollConsumed === true ) this . longContextRollConsumed = true ;
477+ const config = this . currentConfig ( ) ;
478+ const inputs = this . gateInputs ( ) ;
479+ const verdict = evaluateSurveyGate ( { ...inputs , config } ) ;
480+ if ( verdict . longContextRollConsumed === true ) {
481+ this . longContextRollConsumedModels . add ( inputs . longContext . kfcModelId ) ;
482+ }
469483 if ( ! verdict . show ) return ;
470484 this . open ( verdict . survey , config ) ;
471485 }
@@ -508,7 +522,12 @@ export class SurveyController {
508522 ...shared ,
509523 cumulativeTokens : appState . cumulativeTokens ?? 0 ,
510524 virtualContextTokens : appState . contextTokens ,
511- mountRollConsumed : this . longContextRollConsumed ,
525+ mountRollConsumed : this . longContextRollConsumedModels . has ( shared . kfcModelId ) ,
526+ mountSurveyShown : this . longContextShownThisMount ,
527+ msSinceGlobalLastShown :
528+ this . globalLastShownAt === undefined
529+ ? undefined
530+ : this . wallNow ( ) - this . globalLastShownAt ,
512531 drawMountRoll : ( ) => ( this . deps . random ?? defaultDeps . random ) ( ) ,
513532 } ,
514533 } ;
@@ -564,7 +583,7 @@ export class SurveyController {
564583 this . openedEditorText = this . host . state . editor . getText ( ) ;
565584 this . lastShownAt = shownAt ;
566585 this . userTurnsAtLastShown = this . userTurnCount ;
567- if ( survey !== 'session ') return ;
586+ if ( survey === 'long_context ') this . longContextShownThisMount = true ;
568587 this . globalLastShownAt = this . wallNow ( ) ;
569588 try {
570589 ( this . deps . writeGlobalLastShown ?? defaultDeps . writeGlobalLastShown ) (
@@ -598,7 +617,7 @@ export class SurveyController {
598617 response : effect . response ,
599618 } ,
600619 this . appearanceSnapshot ?. fields ?? this . environmentFields ( ) ,
601- this . appearanceConfig ?? ( this . deps . config ?? defaultDeps . config ) ( ) ,
620+ this . appearanceConfig ?? this . currentConfig ( ) ,
602621 ) ;
603622 const sessionId = this . appearanceSnapshot ?. sessionId ?? '' ;
604623 if ( sessionId . length > 0 ) {
0 commit comments