Skip to content
Closed
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/agents/memoryManager/tools/workspaces/updateWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@ export class UpdateWorkspaceTool extends BaseTool<UpdateWorkspaceParameters, Upd
if (params.dedicatedAgentId !== undefined) {
if (params.dedicatedAgentId === '') {
// Empty string means remove dedicated agent
(workspaceCopy as any).dedicatedAgentId = undefined;
workspaceCopy.dedicatedAgentId = undefined;
} else {
// Store ID or name as-is (lookup happens on load)
(workspaceCopy as any).dedicatedAgentId = params.dedicatedAgentId;
workspaceCopy.dedicatedAgentId = params.dedicatedAgentId;
}
}

// Update timestamp
workspaceCopy.lastAccessed = now;

console.error('[UpdateWorkspace] Updated dedicatedAgentId:', (workspaceCopy as any).dedicatedAgentId);
console.error('[UpdateWorkspace] Updated dedicatedAgentId:', workspaceCopy.dedicatedAgentId);

// Perform the update
await workspaceService.updateWorkspace(existingWorkspace.id, workspaceCopy);
Expand Down
3 changes: 1 addition & 2 deletions src/agents/promptManager/promptManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { UsageTracker } from '../../services/UsageTracker';
import { Vault, EventRef } from 'obsidian';
import { LLMSettingsNotifier } from '../../services/llm/LLMSettingsNotifier';
import { LLMProviderSettings } from '../../types';
import type { MigratableDatabase } from '../../database/schema/SchemaMigrator';

/**
* PromptManager Agent for custom prompt operations
Expand Down Expand Up @@ -87,7 +86,7 @@ export class PromptManagerAgent extends BaseAgent {
parentAgentManager: AgentManager,
usageTracker: UsageTracker,
vault: Vault,
db?: MigratableDatabase | null
db?: unknown
) {
super(
'promptManager',
Expand Down
19 changes: 13 additions & 6 deletions src/agents/promptManager/services/CustomPromptStorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ import { Settings } from '../../../settings';
import type { MigratableDatabase } from '../../../database/schema/SchemaMigrator';

/**
* Database-like wrapper that adapts raw sqlite db to MigratableDatabase interface
* Extension of MigratableDatabase that adds parameterized query support.
* Used internally by DatabaseAdapter for SELECT operations with parameters.
*/
interface QueryableDatabase extends MigratableDatabase {
query(sql: string, params?: unknown[]): { values: unknown[][] }[];
}

/**
* Database-like wrapper that adapts raw sqlite db to QueryableDatabase interface
* Adds query() method for parameterized SELECT queries
*/
class DatabaseAdapter implements MigratableDatabase {
class DatabaseAdapter implements QueryableDatabase {
constructor(private rawDb: any) {}

exec(sql: string): { values: any[][] }[] {
Expand Down Expand Up @@ -48,7 +56,7 @@ class DatabaseAdapter implements MigratableDatabase {
* Migrated to SQLite-based storage with data.json fallback for backward compatibility
*/
export class CustomPromptStorageService {
private db: MigratableDatabase | null;
private db: QueryableDatabase | null;
private settings: Settings;
private migrated: boolean = false;

Expand Down Expand Up @@ -185,9 +193,8 @@ export class CustomPromptStorageService {
// Try SQLite first if available
if (this.db && this.migrated) {
try {
const adapter = this.db as any;
const result = adapter.query
? adapter.query('SELECT * FROM custom_prompts WHERE id = ? OR name = ? LIMIT 1', [identifier, identifier])
const result = this.db.query
? this.db.query('SELECT * FROM custom_prompts WHERE id = ? OR name = ? LIMIT 1', [identifier, identifier])
: [];

if (result.length > 0 && result[0].values.length > 0) {
Expand Down
80 changes: 47 additions & 33 deletions src/agents/promptManager/tools/executePrompts/executePrompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import {
import {
BudgetValidator,
ContextBuilder,
PromptExecutor,
RequestExecutor,
SequenceManager,
ResultProcessor,
ActionExecutor
} from './services';
PromptExecutor,
RequestExecutor,
SequenceManager,
ResultProcessor,
ActionExecutor,
ExecutionErrorService
} from './services';
import { PromptParser } from './utils';
import { addRecommendations, Recommendation } from '../../../../utils/recommendationUtils';
import { NudgeHelpers } from '../../../../utils/nudgeHelpers';
Expand All @@ -50,11 +51,12 @@ export class ExecutePromptsTool extends BaseTool<BatchExecutePromptParams, Batch
// Specialized services (composition)
private budgetValidator!: BudgetValidator;
private contextBuilder!: ContextBuilder;
private promptExecutor!: PromptExecutor;
private requestExecutor!: RequestExecutor;
private sequenceManager!: SequenceManager;
private resultProcessor!: ResultProcessor;
private actionExecutor!: ActionExecutor;
private promptExecutor!: PromptExecutor;
private requestExecutor!: RequestExecutor;
private sequenceManager!: SequenceManager;
private resultProcessor!: ResultProcessor;
private actionExecutor!: ActionExecutor;
private executionErrorService!: ExecutionErrorService;

// Utilities
private promptParser!: PromptParser;
Expand Down Expand Up @@ -122,21 +124,27 @@ export class ExecutePromptsTool extends BaseTool<BatchExecutePromptParams, Batch
/**
* Ensure request executor is initialized with all dependencies
*/
private ensureRequestExecutor(): void {
if (!this.promptExecutor && this.llmService) {
this.promptExecutor = new PromptExecutor(
this.llmService,
this.budgetValidator,
this.contextBuilder,
this.promptStorage || undefined
);
}

if (!this.requestExecutor && this.promptExecutor && this.actionExecutor) {
this.requestExecutor = new RequestExecutor(
this.promptExecutor,
this.actionExecutor
);
private ensureRequestExecutor(): void {
if (!this.executionErrorService && this.llmService) {
this.executionErrorService = new ExecutionErrorService(this.llmService);
}

if (!this.promptExecutor && this.llmService) {
this.promptExecutor = new PromptExecutor(
this.llmService,
this.budgetValidator,
this.contextBuilder,
this.executionErrorService,
this.promptStorage || undefined
);
}

if (!this.requestExecutor && this.promptExecutor && this.actionExecutor && this.executionErrorService) {
this.requestExecutor = new RequestExecutor(
this.promptExecutor,
this.actionExecutor,
this.executionErrorService
);

this.sequenceManager = new SequenceManager(
this.requestExecutor,
Expand Down Expand Up @@ -226,12 +234,18 @@ export class ExecutePromptsTool extends BaseTool<BatchExecutePromptParams, Batch
processedResults.error
);

// Dynamic nudges based on operation count
const nudges: Recommendation[] = [NudgeHelpers.suggestCaptureProgress()];
const batchNudge = NudgeHelpers.checkBatchAgentOpportunity(processedResults.results?.length || 0);
if (batchNudge) nudges.push(batchNudge);

return addRecommendations(result, nudges);
// Dynamic nudges based on operation count
const nudges: Recommendation[] = [NudgeHelpers.suggestCaptureProgress()];
const batchNudge = NudgeHelpers.checkBatchAgentOpportunity(processedResults.results?.length || 0);
if (batchNudge) nudges.push(batchNudge);
if (results.some(result => !result.success && result.error && this.executionErrorService.isApiKeyIssue(result.error))) {
nudges.push({
type: 'llm_configuration',
message: 'Some prompts failed authentication. Update provider API keys in Settings > LLM Providers, then retry.'
});
}

return addRecommendations(result, nudges);

} catch (error) {
console.error('Batch LLM prompt execution failed:', error);
Expand Down Expand Up @@ -487,4 +501,4 @@ export class ExecutePromptsTool extends BaseTool<BatchExecutePromptParams, Batch
required: ['success']
};
}
}
}
Loading