From c368e513b0a21f893ca9dde26e094e3c74c25f8c Mon Sep 17 00:00:00 2001 From: mkorwel Date: Thu, 19 Mar 2026 09:48:57 -0700 Subject: [PATCH] refactor(workspaces): improve UI typing and remove unnecessary casts --- .../cli/src/ui/commands/workspaceCommand.ts | 17 ++++++++--------- .../cli/src/ui/hooks/slashCommandProcessor.ts | 5 +++++ packages/cli/src/ui/types.ts | 5 +++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/ui/commands/workspaceCommand.ts b/packages/cli/src/ui/commands/workspaceCommand.ts index 177368b7eb..892522d7c2 100644 --- a/packages/cli/src/ui/commands/workspaceCommand.ts +++ b/packages/cli/src/ui/commands/workspaceCommand.ts @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import type { SlashCommand, CommandContext } from './types.js'; +import type { SlashCommand, CommandContext, SlashCommandActionReturn } from './types.js'; import { CommandKind } from './types.js'; import { type CommandActionReturn, @@ -60,7 +60,7 @@ const createCommand: SlashCommand = { action: (async ( context: CommandContext, args: string, - ): Promise => { + ): Promise => { const name = args.trim(); if (!name) { return { @@ -78,7 +78,7 @@ const createCommand: SlashCommand = { context.ui.addItem({ type: 'info', text: `Requesting creation of workspace "${name}"...`, - }); + } as any); const ws = await client.createWorkspace(name); return { type: 'message', @@ -105,7 +105,7 @@ const deleteCommand: SlashCommand = { action: (async ( _context: CommandContext, args: string, - ): Promise => { + ): Promise => { const id = args.trim(); if (!id) { return { @@ -120,11 +120,10 @@ const deleteCommand: SlashCommand = { const client = new WorkspaceHubClient(hubUrl); try { - // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access - (_context.ui as any).addItem({ + _context.ui.addItem({ type: 'info', text: `Deleting workspace "${id}"...`, - }); + } as any); await client.deleteWorkspace(id); return { type: 'message', @@ -150,7 +149,7 @@ const connectCommand: SlashCommand = { action: (async ( _context: CommandContext, args: string, - ): Promise => { + ): Promise => { const id = args.trim(); if (!id) { return { @@ -173,5 +172,5 @@ export const workspaceSlashCommand: SlashCommand = { kind: CommandKind.BUILT_IN, autoExecute: false, subCommands: [listCommand, createCommand, deleteCommand, connectCommand], - action: (async (context: CommandContext) => listAction(context)) as any, + action: ((context: CommandContext) => listAction(context)) as any, }; diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts index f10f9afd27..76e0177eb4 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts @@ -196,6 +196,11 @@ export const useSlashCommandProcessor = ( type: 'compression', compression: message.compression, }; + } else if (message.type === MessageType.WORKSPACES_LIST) { + historyItemContent = { + type: 'workspaces_list', + workspaces: message.workspaces, + }; } else { historyItemContent = { type: message.type, diff --git a/packages/cli/src/ui/types.ts b/packages/cli/src/ui/types.ts index f2bf69eeb3..5d1d146ee4 100644 --- a/packages/cli/src/ui/types.ts +++ b/packages/cli/src/ui/types.ts @@ -466,6 +466,11 @@ export type Message = type: MessageType.COMPRESSION; compression: CompressionProps; timestamp: Date; + } + | { + type: MessageType.WORKSPACES_LIST; + timestamp: Date; + workspaces: WorkspaceHubInfo[]; }; export interface ConsoleMessageItem {