UNPKG

lanonasis-memory

Version:

Memory as a Service integration - AI-powered memory management with semantic search (Compatible with CLI v3.0.6+)

230 lines 9.77 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ApiKeyTreeProvider = exports.ProjectTreeItem = exports.ApiKeyTreeItem = void 0; const vscode = __importStar(require("vscode")); class ApiKeyTreeItem extends vscode.TreeItem { constructor(apiKey, collapsibleState) { super(apiKey.name, collapsibleState); this.apiKey = apiKey; this.tooltip = `${apiKey.name}\nType: ${apiKey.keyType}\nEnvironment: ${apiKey.environment}\nAccess Level: ${apiKey.accessLevel}`; this.description = `${apiKey.environment} • ${apiKey.keyType}`; this.contextValue = 'apiKey'; // Set icon based on key type this.iconPath = this.getIconForKeyType(apiKey.keyType); // Add expiration warning if key expires soon if (apiKey.expiresAt) { const expiresAt = new Date(apiKey.expiresAt); const now = new Date(); const daysUntilExpiry = Math.floor((expiresAt.getTime() - now.getTime()) / (1000 * 60 * 60 * 24)); if (daysUntilExpiry <= 7) { this.description += ` ⚠️ Expires in ${daysUntilExpiry} days`; } } } getIconForKeyType(keyType) { const iconMap = { 'api_key': 'key', 'database_url': 'database', 'oauth_token': 'account', 'certificate': 'certificate', 'ssh_key': 'terminal', 'webhook_secret': 'webhook', 'encryption_key': 'shield' }; return new vscode.ThemeIcon(iconMap[keyType] || 'key'); } } exports.ApiKeyTreeItem = ApiKeyTreeItem; class ProjectTreeItem extends vscode.TreeItem { constructor(project, collapsibleState) { super(project.name, collapsibleState); this.project = project; this.tooltip = `${project.name}\n${project.description || 'No description'}\nOrganization: ${project.organizationId}`; this.description = project.description ? project.description.substring(0, 50) + '...' : 'No description'; this.contextValue = 'project'; this.iconPath = new vscode.ThemeIcon('folder'); } } exports.ProjectTreeItem = ProjectTreeItem; class ApiKeyTreeProvider { constructor(apiKeyService) { this.apiKeyService = apiKeyService; this._onDidChangeTreeData = new vscode.EventEmitter(); this.onDidChangeTreeData = this._onDidChangeTreeData.event; this.projects = []; this.apiKeys = {}; this.authenticated = false; } refresh(resetCache = false) { if (resetCache) { this.clearCache(); } this._onDidChangeTreeData.fire(); } setAuthenticated(authenticated) { this.authenticated = authenticated; if (!authenticated) { this.clear(); } else { this.clear(); this.refresh(); } } clear() { this.clearCache(); this._onDidChangeTreeData.fire(); } getTreeItem(element) { return element; } async getChildren(element) { if (!this.authenticated) { const authItem = new vscode.TreeItem('Not authenticated', vscode.TreeItemCollapsibleState.None); authItem.description = 'Click to authenticate'; authItem.iconPath = new vscode.ThemeIcon('key'); authItem.contextValue = 'notAuthenticated'; authItem.command = { command: 'lanonasis.authenticate', title: 'Authenticate', arguments: ['oauth'] }; return [authItem]; } try { if (!element) { // Root level - show projects this.projects = await this.apiKeyService.getProjects(); if (this.projects.length === 0) { // Return a message item when no projects exist const emptyItem = new vscode.TreeItem('No projects found', vscode.TreeItemCollapsibleState.None); emptyItem.description = 'Click + to create a project'; emptyItem.iconPath = new vscode.ThemeIcon('info'); emptyItem.contextValue = 'empty'; return [emptyItem]; } return this.projects.map(project => new ProjectTreeItem(project, vscode.TreeItemCollapsibleState.Collapsed)); } else if (element instanceof ProjectTreeItem) { // Project level - show API keys for this project const projectId = element.project.id; if (!this.apiKeys[projectId]) { this.apiKeys[projectId] = await this.apiKeyService.getApiKeys(projectId); } if (this.apiKeys[projectId].length === 0) { // Return a message item when no keys exist const emptyItem = new vscode.TreeItem('No API keys in this project', vscode.TreeItemCollapsibleState.None); emptyItem.description = 'Right-click project to create a key'; emptyItem.iconPath = new vscode.ThemeIcon('info'); emptyItem.contextValue = 'empty'; return [emptyItem]; } return this.apiKeys[projectId].map(apiKey => new ApiKeyTreeItem(apiKey, vscode.TreeItemCollapsibleState.None)); } } catch (error) { console.error('Error loading API keys:', error); const errorMsg = error instanceof Error ? error.message : 'Unknown error'; // Check if it's an authentication error if (errorMsg.includes('401') || errorMsg.includes('No token') || errorMsg.includes('AUTH_TOKEN_MISSING')) { const authItem = new vscode.TreeItem('Authentication required', vscode.TreeItemCollapsibleState.None); authItem.description = 'Click to authenticate'; authItem.iconPath = new vscode.ThemeIcon('warning'); authItem.contextValue = 'authRequired'; authItem.command = { command: 'lanonasis.authenticate', title: 'Authenticate', arguments: ['oauth'] }; authItem.tooltip = `Authentication error: ${errorMsg}`; return [authItem]; } const errorItem = new vscode.TreeItem('Error loading data', vscode.TreeItemCollapsibleState.None); errorItem.description = errorMsg.length > 50 ? errorMsg.substring(0, 50) + '...' : errorMsg; errorItem.iconPath = new vscode.ThemeIcon('error'); errorItem.contextValue = 'error'; errorItem.tooltip = errorMsg; return [errorItem]; } return []; } // Utility methods for managing the tree async addProject(project) { this.projects.push(project); this.refresh(); } async updateProject(updatedProject) { const index = this.projects.findIndex(p => p.id === updatedProject.id); if (index !== -1) { this.projects[index] = updatedProject; this.refresh(); } } async removeProject(projectId) { this.projects = this.projects.filter(p => p.id !== projectId); delete this.apiKeys[projectId]; this.refresh(); } async addApiKey(projectId, apiKey) { if (!this.apiKeys[projectId]) { this.apiKeys[projectId] = []; } this.apiKeys[projectId].push(apiKey); this.refresh(); } async updateApiKey(projectId, updatedApiKey) { if (this.apiKeys[projectId]) { const index = this.apiKeys[projectId].findIndex(k => k.id === updatedApiKey.id); if (index !== -1) { this.apiKeys[projectId][index] = updatedApiKey; this.refresh(); } } } async removeApiKey(projectId, apiKeyId) { if (this.apiKeys[projectId]) { this.apiKeys[projectId] = this.apiKeys[projectId].filter(k => k.id !== apiKeyId); this.refresh(); } } // Clear cache when refreshing clearCache() { this.projects = []; this.apiKeys = {}; } } exports.ApiKeyTreeProvider = ApiKeyTreeProvider; //# sourceMappingURL=ApiKeyTreeProvider.js.map