Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/ui/chat/components/ChatSettingsModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,7 @@ export class ChatSettingsModal extends Modal {

// Update workspace
if (settings.workspaceId) {
const workspace = await this.workspaceService.getWorkspace(settings.workspaceId);
if (workspace?.context) {
await this.modelAgentManager.setWorkspaceContext(settings.workspaceId, workspace.context);
}
await this.modelAgentManager.setWorkspaceContext(settings.workspaceId);
} else {
await this.modelAgentManager.clearWorkspaceContext();
}
Expand Down
109 changes: 3 additions & 106 deletions src/ui/chat/services/ModelAgentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { ModelOption, PromptOption } from '../types/SelectionTypes';
import { WorkspaceContext } from '../../../database/types/workspace/WorkspaceTypes';
import { MessageEnhancement } from '../components/suggesters/base/SuggesterInterfaces';
import { SystemPromptBuilder, PromptSummary, ToolAgentInfo, ContextStatusInfo } from './SystemPromptBuilder';
import { SystemPromptBuilder, ContextStatusInfo } from './SystemPromptBuilder';
import { ContextNotesManager } from './ContextNotesManager';
import { ModelSelectionUtility } from '../utils/ModelSelectionUtility';
import { PromptConfigurationUtility } from '../utils/PromptConfigurationUtility';
Expand Down Expand Up @@ -86,25 +86,6 @@ interface ConversationServiceLike {
updateConversationMetadata(conversationId: string, metadata: Record<string, unknown>): Promise<void>;
}

interface AgentToolLike {
slug?: string;
name?: string;
}

interface AgentLike {
description?: string;
getTools?: () => AgentToolLike[];
}

/**
* App type with plugin registry access
*/
type AppWithPlugins = {
plugins?: {
plugins?: Record<string, NexusPlugin>;
};
} & Omit<App, 'plugins'>;

/**
* Plugin interface with settings structure
*/
Expand All @@ -125,11 +106,6 @@ interface PluginWithSettings {
serviceManager?: {
getServiceIfReady?: (name: string) => unknown;
};
connector?: {
agentRegistry?: {
getAllAgents: () => Map<string, AgentLike>;
};
};
}

export interface ModelAgentManagerEvents {
Expand Down Expand Up @@ -647,9 +623,8 @@ export class ModelAgentManager {
* When a workspace is selected in chat settings, load the same rich data
* as the #workspace suggester (file structure, sessions, states, etc.)
*/
async setWorkspaceContext(workspaceId: string, context: WorkspaceContext): Promise<void> {
async setWorkspaceContext(workspaceId: string): Promise<void> {
this.selectedWorkspaceId = workspaceId;
this.workspaceContext = context; // Keep basic context for backward compatibility

// Load full comprehensive workspace data (same as #workspace suggester)
try {
Expand Down Expand Up @@ -1035,12 +1010,6 @@ export class ModelAgentManager {
private async buildSystemPromptWithWorkspace(): Promise<string | null> {
const sessionId = await this.getCurrentSessionId();

// Fetch dynamic context (always fresh)
const vaultStructure = this.workspaceIntegration.getVaultStructure();
const availableWorkspaces = await this.workspaceIntegration.listAvailableWorkspaces();
const availablePrompts = await this.getAvailablePromptSummaries();
const toolAgents = this.getToolAgentInfo();

// Skip tools section for Nexus/WebLLM - it's pre-trained on the toolset
const isNexusModel = this.selectedModel?.providerId === 'webllm';

Expand All @@ -1064,12 +1033,7 @@ export class ModelAgentManager {
messageEnhancement: this.messageEnhancement,
customPrompt: this.currentSystemPrompt,
workspaceContext: this.workspaceContext,
loadedWorkspaceData: this.loadedWorkspaceData, // Full comprehensive workspace data
// Dynamic context (always loaded fresh)
vaultStructure,
availableWorkspaces,
availablePrompts,
toolAgents,
loadedWorkspaceData: this.loadedWorkspaceData,
// Nexus models are pre-trained on the toolset - skip tools section
skipToolsSection: isNexusModel,
// Context status for token-limited models
Expand Down Expand Up @@ -1118,73 +1082,6 @@ export class ModelAgentManager {
return this.hasCompactionFrontier();
}

/**
* Get available prompts as summaries for system prompt
* Note: These are user-created prompts, displayed in system prompt for LLM awareness
*/
private async getAvailablePromptSummaries(): Promise<PromptSummary[]> {
const prompts = await this.getAvailablePrompts();
return prompts.map(prompt => ({
id: prompt.id,
name: prompt.name,
description: prompt.description || 'Custom prompt'
}));
}

/**
* Get tool agents info from agent registry for system prompt
* Returns agent names, descriptions, and their available tools
*/
private getToolAgentInfo(): ToolAgentInfo[] {
try {
// Access plugin from app
const appWithPlugins = this.app as unknown as AppWithPlugins;
const plugin = appWithPlugins.plugins?.plugins?.['claudesidian-mcp'] as unknown as PluginWithSettings | undefined;
if (!plugin) {
return [];
}

// Try agentRegistrationService first (works on both desktop and mobile)
const agentService = plugin.serviceManager?.getServiceIfReady?.('agentRegistrationService');
if (agentService) {
const typedAgentService = agentService as { getAllAgents: () => Map<string, AgentLike> | Array<{ name: string } & AgentLike> };
const agents = typedAgentService.getAllAgents();
const agentMap = agents instanceof Map ? agents : new Map(agents.map((a) => [a.name, a]));

return Array.from(agentMap.entries()).map(([name, agent]) => {
const agentTools = agent.getTools?.() || [];
return {
name,
description: agent.description || '',
tools: agentTools.map(t => t.slug || t.name || 'unknown')
};
});
}

// Fallback to connector's agentRegistry (desktop only)
const connector = plugin.connector;
if (connector?.agentRegistry) {
const agents = connector.agentRegistry.getAllAgents();
const result: ToolAgentInfo[] = [];

for (const [name, agent] of agents) {
const agentTools = agent.getTools?.() || [];
result.push({
name,
description: agent.description || '',
tools: agentTools.map(t => t.slug || t.name || 'unknown')
});
}

return result;
}

return [];
} catch {
return [];
}
}

/**
* Get current session ID from conversation
*/
Expand Down
6 changes: 0 additions & 6 deletions src/ui/chat/services/SystemPromptBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ export interface SystemPromptOptions {
workspaceContext?: WorkspaceContext | null;
// Full comprehensive workspace data from LoadWorkspaceTool (when workspace selected in settings)
loadedWorkspaceData?: LoadedWorkspaceData | null;
// Dynamic context (always loaded fresh)
vaultStructure?: VaultStructure | null;
availableWorkspaces?: WorkspaceSummary[];
availablePrompts?: PromptSummary[];
// Tool agents with their tools (dynamically loaded from agent registry)
toolAgents?: ToolAgentInfo[];
// Skip the tools section for models that are pre-trained on the toolset (e.g., Nexus)
skipToolsSection?: boolean;
// Context status for token-limited models (enables context awareness)
Expand Down