1- import type { PermissionMode , Session } from '@moonshot-ai/kimi-code-sdk' ;
1+ import type {
2+ ExperimentalFeatureState ,
3+ FlagId ,
4+ PermissionMode ,
5+ Session ,
6+ } from '@moonshot-ai/kimi-code-sdk' ;
27
38import { EditorSelectorComponent } from '../components/dialogs/editor-selector' ;
9+ import {
10+ ExperimentsSelectorComponent ,
11+ type ExperimentalFeatureDraftChange ,
12+ } from '../components/dialogs/experiments-selector' ;
413import { TabbedModelSelectorComponent } from '../components/dialogs/tabbed-model-selector' ;
514import { PermissionSelectorComponent } from '../components/dialogs/permission-selector' ;
615import { SettingsSelectorComponent , type SettingsSelection } from '../components/dialogs/settings-selector' ;
@@ -12,6 +21,7 @@ import { NO_ACTIVE_SESSION_MESSAGE } from '../constant/kimi-tui';
1221import { isTheme } from '../theme/index' ;
1322import { formatErrorMessage } from '../utils/event-payload' ;
1423import { showUsage } from './info' ;
24+ import { setExperimentalFeatures } from './experimental-flags' ;
1525import type { SlashCommandHost } from './dispatch' ;
1626
1727// ---------------------------------------------------------------------------
@@ -421,6 +431,73 @@ export function showUpdatePreferencePicker(host: SlashCommandHost): void {
421431 ) ;
422432}
423433
434+ export async function showExperimentsPanel ( host : SlashCommandHost ) : Promise < void > {
435+ let features : readonly ExperimentalFeatureState [ ] ;
436+ try {
437+ features = await host . harness . getExperimentalFeatures ( ) ;
438+ } catch ( error ) {
439+ host . showError ( `Failed to load experimental features: ${ formatErrorMessage ( error ) } ` ) ;
440+ return ;
441+ }
442+ mountExperimentsPanel ( host , features ) ;
443+ }
444+
445+ export async function applyExperimentalFeatureChanges (
446+ host : SlashCommandHost ,
447+ changes : readonly ExperimentalFeatureDraftChange [ ] ,
448+ ) : Promise < void > {
449+ if ( changes . length === 0 ) {
450+ host . showStatus (
451+ 'No experimental feature changes to apply.' ,
452+ host . state . theme . colors . textMuted ,
453+ ) ;
454+ return ;
455+ }
456+
457+ const experimental : Partial < Record < FlagId , boolean > > = { } ;
458+ for ( const change of changes ) {
459+ experimental [ change . id ] = change . enabled ;
460+ }
461+
462+ try {
463+ await host . harness . setConfig ( { experimental } ) ;
464+ const features = await host . harness . getExperimentalFeatures ( ) ;
465+ setExperimentalFeatures ( features ) ;
466+ host . refreshSlashCommandAutocomplete ( ) ;
467+ host . restoreEditor ( ) ;
468+ if ( host . session !== undefined ) {
469+ await host . session . reloadSession ( ) ;
470+ await host . reloadCurrentSessionView (
471+ host . session ,
472+ 'Experimental features updated. Session reloaded.' ,
473+ ) ;
474+ } else {
475+ host . showStatus ( 'Experimental features updated.' , host . state . theme . colors . success ) ;
476+ }
477+ host . track ( 'experimental_features_apply' , { changed : changes . length } ) ;
478+ } catch ( error ) {
479+ host . showError ( `Failed to update experimental features: ${ formatErrorMessage ( error ) } ` ) ;
480+ }
481+ }
482+
483+ function mountExperimentsPanel (
484+ host : SlashCommandHost ,
485+ features : readonly ExperimentalFeatureState [ ] ,
486+ ) : void {
487+ host . mountEditorReplacement (
488+ new ExperimentsSelectorComponent ( {
489+ features,
490+ colors : host . state . theme . colors ,
491+ onApply : ( changes ) => {
492+ void applyExperimentalFeatureChanges ( host , changes ) ;
493+ } ,
494+ onCancel : ( ) => {
495+ host . restoreEditor ( ) ;
496+ } ,
497+ } ) ,
498+ ) ;
499+ }
500+
424501type UpdatePreferenceHost = {
425502 readonly state : {
426503 readonly appState : Pick <
@@ -503,6 +580,7 @@ function handleSettingsSelection(host: SlashCommandHost, value: SettingsSelectio
503580 case 'permission' : showPermissionPicker ( host ) ; return ;
504581 case 'theme' : showThemePicker ( host ) ; return ;
505582 case 'editor' : showEditorPicker ( host ) ; return ;
583+ case 'experiments' : void showExperimentsPanel ( host ) ; return ;
506584 case 'upgrade' : showUpdatePreferencePicker ( host ) ; return ;
507585 case 'usage' : void showUsage ( host ) ; return ;
508586 }
0 commit comments