mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 12:03:49 +00:00
feat: add terminal input hook for extensions
This commit is contained in:
parent
6da488a5aa
commit
30fd99bd82
7 changed files with 47 additions and 0 deletions
|
|
@ -123,6 +123,7 @@ export type {
|
|||
SetLabelHandler,
|
||||
SetModelHandler,
|
||||
SetThinkingLevelHandler,
|
||||
TerminalInputHandler,
|
||||
// Events - Tool
|
||||
ToolCallEvent,
|
||||
ToolCallEventResult,
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@ const noOpUIContext: ExtensionUIContext = {
|
|||
confirm: async () => false,
|
||||
input: async () => undefined,
|
||||
notify: () => {},
|
||||
onTerminalInput: () => () => {},
|
||||
setStatus: () => {},
|
||||
setWorkingMessage: () => {},
|
||||
setWidget: () => {},
|
||||
|
|
|
|||
|
|
@ -97,6 +97,9 @@ export interface ExtensionWidgetOptions {
|
|||
placement?: WidgetPlacement;
|
||||
}
|
||||
|
||||
/** Raw terminal input listener for extensions. */
|
||||
export type TerminalInputHandler = (data: string) => { consume?: boolean; data?: string } | undefined;
|
||||
|
||||
/**
|
||||
* UI context for extensions to request interactive UI.
|
||||
* Each mode (interactive, RPC, print) provides its own implementation.
|
||||
|
|
@ -114,6 +117,9 @@ export interface ExtensionUIContext {
|
|||
/** Show a notification to the user. */
|
||||
notify(message: string, type?: "info" | "warning" | "error"): void;
|
||||
|
||||
/** Listen to raw terminal input (interactive mode only). Returns an unsubscribe function. */
|
||||
onTerminalInput(handler: TerminalInputHandler): () => void;
|
||||
|
||||
/** Set status text in the footer/status bar. Pass undefined to clear. */
|
||||
setStatus(key: string, text: string | undefined): void;
|
||||
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ export type {
|
|||
SlashCommandInfo,
|
||||
SlashCommandLocation,
|
||||
SlashCommandSource,
|
||||
TerminalInputHandler,
|
||||
ToolCallEvent,
|
||||
ToolDefinition,
|
||||
ToolInfo,
|
||||
|
|
|
|||
|
|
@ -1368,6 +1368,7 @@ export class InteractiveMode {
|
|||
confirm: (title, message, opts) => this.showExtensionConfirm(title, message, opts),
|
||||
input: (title, placeholder, opts) => this.showExtensionInput(title, placeholder, opts),
|
||||
notify: (message, type) => this.showExtensionNotify(message, type),
|
||||
onTerminalInput: (handler) => this.ui.addInputListener(handler),
|
||||
setStatus: (key, text) => this.setExtensionStatus(key, text),
|
||||
setWorkingMessage: (message) => {
|
||||
if (this.loadingAnimation) {
|
||||
|
|
|
|||
|
|
@ -144,6 +144,11 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
|||
} as RpcExtensionUIRequest);
|
||||
},
|
||||
|
||||
onTerminalInput(): () => void {
|
||||
// Raw terminal input not supported in RPC mode
|
||||
return () => {};
|
||||
},
|
||||
|
||||
setStatus(key: string, text: string | undefined): void {
|
||||
// Fire and forget - no response needed
|
||||
output({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue