From d1dedca4da0896d793606b333d0ac3a599d0462a Mon Sep 17 00:00:00 2001 From: laileni Date: Mon, 8 Sep 2025 09:19:18 -0700 Subject: [PATCH] feat: adding required fields for terminal integration in flare --- runtimes/protocol/index.ts | 1 + runtimes/protocol/terminal.ts | 75 +++++++++++++++++++++++++++++++ runtimes/runtimes/base-runtime.ts | 5 +++ runtimes/runtimes/standalone.ts | 5 +++ runtimes/server-interface/lsp.ts | 15 +++++++ 5 files changed, 101 insertions(+) create mode 100644 runtimes/protocol/terminal.ts diff --git a/runtimes/protocol/index.ts b/runtimes/protocol/index.ts index ed08e1a8..2cc0dc4e 100644 --- a/runtimes/protocol/index.ts +++ b/runtimes/protocol/index.ts @@ -11,6 +11,7 @@ export * from './identity-management' export * from './lsp' export * from './notification' export * from './telemetry' +export * from './terminal' export * from './configuration' export * from './window' export * from './workspace' diff --git a/runtimes/protocol/terminal.ts b/runtimes/protocol/terminal.ts new file mode 100644 index 00000000..2b33d344 --- /dev/null +++ b/runtimes/protocol/terminal.ts @@ -0,0 +1,75 @@ +/*! + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +import { RequestType } from 'vscode-languageserver-protocol' + +/** + * Parameters for executing a command in the IDE terminal + */ +export interface ExecuteTerminalCommandParams { + /** + * The command to execute + */ + command: string + + /** + * Working directory for command execution + */ + cwd?: string + + /** + * Environment variables to set for the command + */ + env?: Record + + /** + * Whether to create a new terminal or reuse existing one + */ + createNew?: boolean + + /** + * Name for the terminal (if creating new) + */ + terminalName?: string +} + +/** + * Result of terminal command execution + */ +export interface ExecuteTerminalCommandResult { + /** + * Exit code of the command + */ + exitCode: number + + /** + * Standard output from the command + */ + stdout: string + + /** + * Standard error from the command + */ + stderr: string + + /** + * Whether the command executed successfully + */ + success: boolean + + /** + * Optional message providing additional context + */ + message?: string +} + +/** + * Request type for executing commands in terminal + */ +export const executeTerminalCommandRequest = new RequestType< + ExecuteTerminalCommandParams, + ExecuteTerminalCommandResult, + void +>('aws/terminal/executeCommand') diff --git a/runtimes/runtimes/base-runtime.ts b/runtimes/runtimes/base-runtime.ts index 96a5a3bb..32ec6b8e 100644 --- a/runtimes/runtimes/base-runtime.ts +++ b/runtimes/runtimes/base-runtime.ts @@ -62,6 +62,7 @@ import { listAvailableModelsRequestType, subscriptionDetailsNotificationType, subscriptionUpgradeNotificationType, + executeTerminalCommandRequest, } from '../protocol' import { createConnection } from 'vscode-languageserver/browser' import { @@ -302,6 +303,10 @@ export const baseRuntime = (connections: { reader: MessageReader; writer: Messag lspConnection.onNotification(didChangeDependencyPathsNotificationType, handler) }, }, + terminal: { + executeCommand: (params, token) => + lspConnection.sendRequest(executeTerminalCommandRequest, params, token), + }, } const sdkInitializator: SDKInitializator = Object.assign( diff --git a/runtimes/runtimes/standalone.ts b/runtimes/runtimes/standalone.ts index 54e8bb9f..c4bbeeac 100644 --- a/runtimes/runtimes/standalone.ts +++ b/runtimes/runtimes/standalone.ts @@ -36,6 +36,7 @@ import { getMfaCodeRequestType, CheckDiagnosticsParams, OpenWorkspaceFileParams, + executeTerminalCommandRequest, } from '../protocol' import { ProposedFeatures, createConnection } from 'vscode-languageserver/node' import { @@ -445,6 +446,10 @@ export const standalone = (props: RuntimeProps) => { lspConnection.onNotification(didChangeDependencyPathsNotificationType, handler) }, }, + terminal: { + executeCommand: (params, token) => + lspConnection.sendRequest(executeTerminalCommandRequest, params, token), + }, } const isExperimentalProxy = process.env.EXPERIMENTAL_HTTP_PROXY_SUPPORT === 'true' diff --git a/runtimes/server-interface/lsp.ts b/runtimes/server-interface/lsp.ts index 7a5a43f3..8d91cf10 100644 --- a/runtimes/server-interface/lsp.ts +++ b/runtimes/server-interface/lsp.ts @@ -65,6 +65,9 @@ import { CheckDiagnosticsResult, OpenWorkspaceFileParams, OpenWorkspaceFileResult, + ExecuteTerminalCommandParams, + ExecuteTerminalCommandResult, + CancellationToken, } from '../protocol' // Re-export whole surface of LSP protocol used in Runtimes. @@ -189,4 +192,16 @@ export type Lsp = { onGetConfigurationFromServer: (handler: RequestHandler) => void onDidChangeDependencyPaths: (handler: NotificationHandler) => void } + terminal: { + /** + * Execute a command in the IDE terminal + * @param params Terminal command execution parameters + * @param token Optional cancellation token + * @returns Promise that resolves with the execution result + */ + executeCommand: ( + params: ExecuteTerminalCommandParams, + token?: CancellationToken + ) => Promise + } }