Add extension mode context
This commit is contained in:
@@ -66,6 +66,7 @@ export type {
|
||||
ExtensionFactory,
|
||||
ExtensionFlag,
|
||||
ExtensionHandler,
|
||||
ExtensionMode,
|
||||
// Runtime
|
||||
ExtensionRuntime,
|
||||
ExtensionShortcut,
|
||||
|
||||
@@ -28,6 +28,7 @@ import type {
|
||||
ExtensionError,
|
||||
ExtensionEvent,
|
||||
ExtensionFlag,
|
||||
ExtensionMode,
|
||||
ExtensionRuntime,
|
||||
ExtensionShortcut,
|
||||
ExtensionUIContext,
|
||||
@@ -225,6 +226,7 @@ export class ExtensionRunner {
|
||||
private extensions: Extension[];
|
||||
private runtime: ExtensionRuntime;
|
||||
private uiContext: ExtensionUIContext;
|
||||
private mode: ExtensionMode = "print";
|
||||
private cwd: string;
|
||||
private sessionManager: SessionManager;
|
||||
private modelRegistry: ModelRegistry;
|
||||
@@ -354,8 +356,9 @@ export class ExtensionRunner {
|
||||
this.reloadHandler = async () => {};
|
||||
}
|
||||
|
||||
setUIContext(uiContext?: ExtensionUIContext): void {
|
||||
setUIContext(uiContext?: ExtensionUIContext, mode: ExtensionMode = "print"): void {
|
||||
this.uiContext = uiContext ?? noOpUIContext;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
getUIContext(): ExtensionUIContext {
|
||||
@@ -578,6 +581,10 @@ export class ExtensionRunner {
|
||||
runner.assertActive();
|
||||
return runner.uiContext;
|
||||
},
|
||||
get mode() {
|
||||
runner.assertActive();
|
||||
return runner.mode;
|
||||
},
|
||||
get hasUI() {
|
||||
runner.assertActive();
|
||||
return runner.hasUI();
|
||||
|
||||
@@ -295,10 +295,14 @@ export interface CompactOptions {
|
||||
/**
|
||||
* Context passed to extension event handlers.
|
||||
*/
|
||||
export type ExtensionMode = "tui" | "rpc" | "json" | "print";
|
||||
|
||||
export interface ExtensionContext {
|
||||
/** UI methods for user interaction */
|
||||
ui: ExtensionUIContext;
|
||||
/** Whether UI is available (false in print/RPC mode) */
|
||||
/** Current run mode. Use "tui" to guard terminal-only UI such as custom components. */
|
||||
mode: ExtensionMode;
|
||||
/** Whether dialog-capable UI is available (true in TUI and RPC modes) */
|
||||
hasUI: boolean;
|
||||
/** Current working directory */
|
||||
cwd: string;
|
||||
|
||||
Reference in New Issue
Block a user