mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
Introduce QuickActionsService and QuickAgent for lightweight, single-shot AI operations. Add a dedicated quickActionModel setting alongside a new top-level provider setting, with validation ensuring all models match the selected provider and provider-specific defaults. Refactor FileSystemService to offer both TFile and path-based overloads (readFile/readFilePath, writeToFile/writeToFilePath, patchFile/patchFileAtPath). Replace window/document globals with activeWindow/ activeDocument throughout InputService and VaultkeeperAISettingTab for Obsidian mobile compatibility. Update linting packages to latest.
55 lines
No EOL
2 KiB
TypeScript
55 lines
No EOL
2 KiB
TypeScript
import { AgentType } from "Enums/AgentType";
|
|
import { BaseAgent } from "./BaseAgent";
|
|
import { Conversation } from "Conversations/Conversation";
|
|
import { Exception } from "Helpers/Exception";
|
|
import { AIToolUsageMode } from "Enums/AIToolUsageMode";
|
|
import type { IChatServiceCallbacks } from "Services/ChatService";
|
|
import { ConversationContent } from "Conversations/ConversationContent";
|
|
import { Role } from "Enums/Role";
|
|
|
|
export class QuickAgent extends BaseAgent {
|
|
|
|
public async quickAction(action: string, context: string): Promise<string> {
|
|
|
|
this.setAgentPromptAndTools(action);
|
|
|
|
const conversation = new Conversation();
|
|
const conversationContent = new ConversationContent({
|
|
role: Role.User,
|
|
content: context,
|
|
});
|
|
conversation.contents.push(conversationContent);
|
|
|
|
return await this.requestAgentResponse(AgentType.QuickAction, conversation, this.callbacks());
|
|
}
|
|
|
|
private setAgentPromptAndTools(instruction: string): void {
|
|
if (!this.ai) {
|
|
Exception.throw("Error: No AI provider has been set!");
|
|
}
|
|
this.ai.agentType = AgentType.QuickAction;
|
|
this.ai.aiToolUsageMode = AIToolUsageMode.Disabled;
|
|
this.ai.systemPrompt = instruction;
|
|
this.ai.userInstruction = ""; // do not include user instruction for quick agent
|
|
this.ai.aiToolDefinitions = []; // no tools for quick agent
|
|
}
|
|
|
|
private callbacks(): IChatServiceCallbacks {
|
|
return {
|
|
onSubmit: () => {},
|
|
onStreamingUpdate: () => {},
|
|
onThoughtUpdate: () => {},
|
|
onToolCallStarted: () => {},
|
|
onPlanningStarted: () => {},
|
|
onPlanningFinished: () => {},
|
|
onUserQuestion: async () => {
|
|
return new Promise<string>(() => {});
|
|
},
|
|
onPlanUpdate: () => {},
|
|
onPlanStepUpdate: () => {},
|
|
onPlanReset: () => {},
|
|
onComplete: () => {},
|
|
};
|
|
}
|
|
|
|
} |