@kinvolk/headlamp-plugin
Version:
The needed infrastructure for building Headlamp plugins.
82 lines (70 loc) • 2.32 kB
text/typescript
export type ToolCall = {
id: string;
name: string;
description?: string;
arguments: Record<string, any>;
type: 'mcp' | 'regular';
};
export type AgentThinkingStep = {
id: string;
content: string;
type: 'tool-start' | 'tool-result' | 'intermediate-text' | 'todo-update';
timestamp: number;
};
export type Prompt = {
role: string;
content: string;
toolCalls?: any[];
toolCallId?: string;
name?: string;
error?: boolean;
success?: boolean;
contentFilterError?: boolean;
alreadyDisplayed?: boolean;
isDisplayOnly?: boolean; // Mark messages that shouldn't be sent to LLM
requestId?: string; // For tracking tool confirmation messages
/** Agent-mode thinking steps shown in a collapsible block */
agentThinkingSteps?: AgentThinkingStep[];
/** Whether the agent run is complete (thinking block should collapse) */
agentThinkingDone?: boolean;
// Add support for inline tool confirmations
toolConfirmation?: {
tools: ToolCall[];
onApprove: (approvedToolIds: string[]) => void;
onDeny: () => void;
loading?: boolean;
//TODO: added this, because there was no userContext
userContext?: any; // Additional context about the user or conversation for tool confirmation
};
};
export default abstract class AIManager {
history: Prompt[] = [];
currentContext: string = '';
setContext(contextDescription: string) {
this.currentContext = contextDescription;
}
addContextualInfo(info: string) {
if (this.currentContext) {
this.currentContext += '\n' + info;
} else {
this.currentContext = info;
}
}
reset() {
this.history = [];
this.currentContext = '';
}
// Abstract method that must be implemented
abstract userSend(message: string): Promise<Prompt>;
// Changed from protected to public to allow external calling
abstract processToolResponses(): Promise<Prompt>;
// Abstract method to abort current request
abstract abort(): void;
// Define configureTools method for tool configuration - made generic to support different contexts
configureTools?(tools: any[], context: any): void;
getPromptSuggestions(): string[] {
// Return empty array as suggestions are now dynamically generated by the LLM
// and parsed from responses in the modal component
return [];
}
}