Files
smartkvm/ts/smartkvm.tools.smartagent.ts
T

59 lines
1.8 KiB
TypeScript
Raw Normal View History

2026-05-16 13:41:55 +00:00
import { SmartKvmTerminal } from './smartkvm.classes.kvmterminal.js';
import type { IKvmTerminalCommandResult } from './smartkvm.interfaces.js';
export interface ISmartKvmTool<TInput = unknown, TOutput = unknown> {
name: string;
description: string;
parameters: unknown;
execute: (input: TInput) => Promise<TOutput>;
}
export interface ISmartKvmToolOptions {
terminal: SmartKvmTerminal;
}
export interface ISmartKvmTerminalRunCommandInput {
command: string;
}
export type TSmartKvmTerminalObserveInput = Record<string, never>;
export const createSmartKvmTools = (options: ISmartKvmToolOptions): ISmartKvmTool[] => {
return [
{
name: 'kvm_terminal_run_command',
description: 'Run a command through the visual KVM terminal transport and return OCR-parsed output.',
parameters: {
type: 'object',
properties: {
command: {
type: 'string',
description: 'The terminal command to run.',
},
},
required: ['command'],
additionalProperties: false,
},
execute: async (input: unknown): Promise<IKvmTerminalCommandResult> => {
const typedInput = input as Partial<ISmartKvmTerminalRunCommandInput>;
if (!typedInput || typeof typedInput.command !== 'string') {
throw new Error('kvm_terminal_run_command requires a string command.');
}
return options.terminal.runCommand(typedInput.command);
},
},
{
name: 'kvm_terminal_observe',
description: 'Observe the current visual KVM terminal text through the configured OCR engine.',
parameters: {
type: 'object',
properties: {},
additionalProperties: false,
},
execute: async (): Promise<string> => {
return options.terminal.observeText();
},
},
];
};