ktx/packages/cli/src/setup-ready-menu.ts

67 lines
2.3 KiB
TypeScript
Raw Normal View History

2026-05-10 23:12:26 +02:00
import { cancel, isCancel, select } from '@clack/prompts';
import { withMenuOptionsSpacing } from './prompt-navigation.js';
2026-05-10 23:51:24 +02:00
import type { KtxSetupStatus } from './setup.js';
2026-05-10 23:12:26 +02:00
import { withSetupInterruptConfirmation } from './setup-interrupt.js';
2026-05-10 23:51:24 +02:00
export type KtxSetupReadyAction = 'models' | 'embeddings' | 'databases' | 'sources' | 'context' | 'agents' | 'exit';
2026-05-10 23:12:26 +02:00
2026-05-10 23:51:24 +02:00
export interface KtxSetupReadyMenuPromptAdapter {
2026-05-10 23:12:26 +02:00
select(options: { message: string; options: Array<{ value: string; label: string }> }): Promise<string>;
cancel(message: string): void;
}
2026-05-10 23:51:24 +02:00
export interface KtxSetupReadyMenuDeps {
prompts?: KtxSetupReadyMenuPromptAdapter;
2026-05-10 23:12:26 +02:00
}
2026-05-10 23:13:17 -07:00
export function isKtxPreAgentSetupReady(status: KtxSetupStatus): boolean {
2026-05-10 23:12:26 +02:00
return (
status.project.ready &&
status.llm.ready &&
status.embeddings.ready &&
status.databases.every((database) => database.ready) &&
status.sources.every((source) => source.ready) &&
2026-05-10 23:13:17 -07:00
status.context.ready
2026-05-10 23:12:26 +02:00
);
}
2026-05-10 23:13:17 -07:00
export function isKtxSetupReady(status: KtxSetupStatus): boolean {
return isKtxPreAgentSetupReady(status) && status.agents.some((agent) => agent.ready);
}
2026-05-10 23:51:24 +02:00
function createPromptAdapter(): KtxSetupReadyMenuPromptAdapter {
2026-05-10 23:12:26 +02:00
return {
async select(options) {
const value = await withSetupInterruptConfirmation(() => select(withMenuOptionsSpacing(options)));
if (isCancel(value)) {
cancel('Setup cancelled.');
return 'exit';
}
return String(value);
},
cancel(message) {
cancel(message);
},
};
}
2026-05-10 23:51:24 +02:00
export async function runKtxSetupReadyChangeMenu(
status: KtxSetupStatus,
deps: KtxSetupReadyMenuDeps = {},
): Promise<{ action: KtxSetupReadyAction }> {
2026-05-10 23:12:26 +02:00
const prompts = deps.prompts ?? createPromptAdapter();
const action = (await prompts.select({
2026-05-10 23:51:24 +02:00
message: `KTX is already set up for ${status.project.name ?? status.project.path}. What would you like to change?`,
2026-05-10 23:12:26 +02:00
options: [
{ value: 'models', label: 'Models' },
{ value: 'embeddings', label: 'Embeddings' },
{ value: 'databases', label: 'Primary sources' },
{ value: 'sources', label: 'Context sources' },
2026-05-10 23:51:24 +02:00
{ value: 'context', label: 'Rebuild KTX context' },
2026-05-10 23:12:26 +02:00
{ value: 'agents', label: 'Agent integration' },
{ value: 'exit', label: 'Exit' },
],
2026-05-10 23:51:24 +02:00
})) as KtxSetupReadyAction;
2026-05-10 23:12:26 +02:00
return { action };
}