@@ -16,6 +16,7 @@ import type { Toast } from "@/browser/components/ChatInputToast";
1616import type { ParsedCommand } from "@/browser/utils/slashCommands/types" ;
1717import { applyCompactionOverrides } from "@/browser/utils/messages/compactionOptions" ;
1818import { resolveCompactionModel } from "@/browser/utils/messages/compactionModelPreference" ;
19+ import { dispatchWorkspaceSwitch } from "./workspaceEvents" ;
1920import { getRuntimeKey , copyWorkspaceStorage } from "@/common/constants/storage" ;
2021
2122// ============================================================================
@@ -110,7 +111,15 @@ export async function processSlashCommand(
110111 context : SlashCommandContext
111112) : Promise < CommandHandlerResult > {
112113 if ( ! parsed ) return { clearInput : false , toastShown : false } ;
113- const { setInput, setIsSending, setToast, variant, setVimEnabled, setPreferredModel, onModelChange } = context ;
114+ const {
115+ setInput,
116+ setIsSending,
117+ setToast,
118+ variant,
119+ setVimEnabled,
120+ setPreferredModel,
121+ onModelChange,
122+ } = context ;
114123
115124 // 1. Global Commands
116125 if ( parsed . type === "providers-set" ) {
@@ -178,7 +187,7 @@ export async function processSlashCommand(
178187 const workspaceCommands = [ "clear" , "truncate" , "compact" , "fork" , "new" ] ;
179188 const isWorkspaceCommand = workspaceCommands . includes ( parsed . type ) ;
180189
181- if ( isWorkspaceCommand ) {
190+ if ( isWorkspaceCommand ) {
182191 if ( variant !== "workspace" ) {
183192 setToast ( {
184193 id : Date . now ( ) . toString ( ) ,
@@ -197,12 +206,18 @@ export async function processSlashCommand(
197206 case "compact" :
198207 // handleCompactCommand expects workspaceId in context
199208 if ( ! context . workspaceId ) throw new Error ( "Workspace ID required" ) ;
200- return handleCompactCommand ( parsed , { ...context , workspaceId : context . workspaceId } as CommandHandlerContext ) ;
209+ return handleCompactCommand ( parsed , {
210+ ...context ,
211+ workspaceId : context . workspaceId ,
212+ } as CommandHandlerContext ) ;
201213 case "fork" :
202214 return handleForkCommand ( parsed , context ) ;
203215 case "new" :
204216 if ( ! context . workspaceId ) throw new Error ( "Workspace ID required" ) ;
205- return handleNewCommand ( parsed , { ...context , workspaceId : context . workspaceId } as CommandHandlerContext ) ;
217+ return handleNewCommand ( parsed , {
218+ ...context ,
219+ workspaceId : context . workspaceId ,
220+ } as CommandHandlerContext ) ;
206221 }
207222 }
208223
@@ -225,10 +240,10 @@ async function handleClearCommand(
225240 context : SlashCommandContext
226241) : Promise < CommandHandlerResult > {
227242 const { setInput, onTruncateHistory, resetInputHeight, setToast } = context ;
228-
243+
229244 setInput ( "" ) ;
230245 resetInputHeight ( ) ;
231-
246+
232247 if ( ! onTruncateHistory ) return { clearInput : true , toastShown : false } ;
233248
234249 try {
@@ -240,11 +255,12 @@ async function handleClearCommand(
240255 } ) ;
241256 return { clearInput : true , toastShown : true } ;
242257 } catch ( error ) {
243- console . error ( "Failed to clear history:" , error ) ;
258+ const normalized = error instanceof Error ? error : new Error ( "Failed to clear history" ) ;
259+ console . error ( "Failed to clear history:" , normalized ) ;
244260 setToast ( {
245261 id : Date . now ( ) . toString ( ) ,
246262 type : "error" ,
247- message : "Failed to clear history" ,
263+ message : normalized . message ,
248264 } ) ;
249265 return { clearInput : false , toastShown : true } ;
250266 }
@@ -270,11 +286,12 @@ async function handleTruncateCommand(
270286 } ) ;
271287 return { clearInput : true , toastShown : true } ;
272288 } catch ( error ) {
273- console . error ( "Failed to truncate history:" , error ) ;
289+ const normalized = error instanceof Error ? error : new Error ( "Failed to truncate history" ) ;
290+ console . error ( "Failed to truncate history:" , normalized ) ;
274291 setToast ( {
275292 id : Date . now ( ) . toString ( ) ,
276293 type : "error" ,
277- message : "Failed to truncate history" ,
294+ message : normalized . message ,
278295 } ) ;
279296 return { clearInput : false , toastShown : true } ;
280297 }
@@ -320,22 +337,20 @@ async function handleForkCommand(
320337 return { clearInput : true , toastShown : true } ;
321338 }
322339 } catch ( error ) {
323- const errorMsg = error instanceof Error ? error . message : "Failed to fork workspace" ;
324- console . error ( "Fork error:" , error ) ;
340+ const normalized = error instanceof Error ? error : new Error ( "Failed to fork workspace" ) ;
341+ console . error ( "Fork error:" , normalized ) ;
325342 setToast ( {
326343 id : Date . now ( ) . toString ( ) ,
327344 type : "error" ,
328345 title : "Fork Failed" ,
329- message : errorMsg ,
346+ message : normalized . message ,
330347 } ) ;
331348 return { clearInput : false , toastShown : true } ;
332349 } finally {
333350 setIsSending ( false ) ;
334351 }
335352}
336353
337-
338-
339354/**
340355 * Parse runtime string from -r flag into RuntimeConfig for backend
341356 * Supports formats:
@@ -479,11 +494,9 @@ export function formatNewCommand(
479494}
480495
481496// ============================================================================
482- // Workspace Forking (re-exported from workspaceFork for convenience )
497+ // Workspace Forking (Inline implementation )
483498// ============================================================================
484499
485- export { forkWorkspace } ;
486-
487500// ============================================================================
488501// Compaction
489502// ============================================================================
@@ -771,10 +784,3 @@ export async function handleCompactCommand(
771784/**
772785 * Dispatch a custom event to switch workspaces
773786 */
774- export function dispatchWorkspaceSwitch ( workspaceInfo : FrontendWorkspaceMetadata ) : void {
775- window . dispatchEvent (
776- new CustomEvent ( CUSTOM_EVENTS . WORKSPACE_FORK_SWITCH , {
777- detail : workspaceInfo ,
778- } )
779- ) ;
780- }
0 commit comments