Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | import * as vscode from "vscode"; import { DataFlintCopilotMcpServer } from "@dataflint/mcp-server"; import { Logger } from "./logger"; import type { OnboardingState } from "./onboarding/onboarding-state"; let statusBarItem: vscode.StatusBarItem; export type StatusBarState = | "setup_needed" | "connected" | "disconnected" | "loading" | "error" | "token_expiring"; export interface StatusBarContext { state: StatusBarState; message?: string; tokenExpiresInMinutes?: number; } interface StatusConfig { icon: string; color?: "warning" | "error"; command?: string; } const STATUS_CONFIG: Record<StatusBarState, StatusConfig> = { setup_needed: { icon: "rocket", color: "warning", command: "dataflint-copilot.openOnboarding", }, connected: { icon: "vm-active", command: "dataflint-copilot.showDebugInfo", }, token_expiring: { icon: "warning", color: "warning", command: "dataflint-copilot.login", }, loading: { icon: "sync~spin" }, error: { icon: "error", color: "error", command: "dataflint-copilot.showLogs", }, disconnected: { icon: "plug", color: "warning", command: "dataflint-copilot.login", }, }; export function createStatusBarItem(): void { statusBarItem = vscode.window.createStatusBarItem( vscode.StatusBarAlignment.Right, 100 ); statusBarItem.hide(); } export function setStatusBarLoading(message: string = "Connecting..."): void { if (!statusBarItem) return; applyStatusConfig({ state: "loading", message }); } export function setStatusBarError(message: string): void { if (!statusBarItem) return; applyStatusConfig({ state: "error", message: `Error: ${message}` }); } function buildTooltip(context: StatusBarContext): string { const { state, message, tokenExpiresInMinutes } = context; const base = "DataFlint"; switch (state) { case "setup_needed": return `${base} — Set up\nClick to open the welcome wizard`; case "connected": return tokenExpiresInMinutes !== undefined ? `${base} - Connected\nToken expires in ${tokenExpiresInMinutes} min` : `${base} - Connected`; case "token_expiring": return `${base} - Token expires in ${tokenExpiresInMinutes || "?"} min\nClick to refresh`; case "loading": return `${base} - ${message || "Loading..."}`; case "error": return `${base} - ${message || "Error occurred"}\nClick to view logs`; case "disconnected": default: return message ? `${base} - ${message}\nClick to login` : `${base} - Disconnected\nClick to login`; } } function applyStatusConfig(context: StatusBarContext): void { if (!statusBarItem) return; const config = STATUS_CONFIG[context.state] ?? STATUS_CONFIG.disconnected; const label = context.state === "setup_needed" ? "Set up DataFlint" : "DataFlint"; statusBarItem.text = `$(${config.icon}) ${label}`; statusBarItem.color = config.color ? new vscode.ThemeColor(`statusBarItem.${config.color}Foreground`) : undefined; statusBarItem.tooltip = buildTooltip(context); statusBarItem.command = config.command; statusBarItem.show(); } function updateStatusBarItem(context: StatusBarContext): void { applyStatusConfig(context); } export async function checkAndUpdateAuthStatus( mcpServer: DataFlintCopilotMcpServer | null, onboardingState?: OnboardingState ): Promise<void> { const logger = Logger.getInstance(); try { if (onboardingState && !onboardingState.isCompleted()) { updateStatusBarItem({ state: "setup_needed" }); return; } if (!mcpServer) { updateStatusBarItem({ state: "disconnected", message: "Server not running", }); return; } const isAuthenticated = await mcpServer.isAuthenticated(); if (!isAuthenticated) { updateStatusBarItem({ state: "disconnected", message: "Not authenticated", }); return; } const currentAuth = mcpServer.getCurrentAuth(); if (!currentAuth?.expiresAt) { updateStatusBarItem({ state: "connected" }); return; } const minutesUntilExpiry = Math.floor( (new Date(currentAuth.expiresAt).getTime() - Date.now()) / 60000 ); if (minutesUntilExpiry <= 15 && minutesUntilExpiry > 0) { updateStatusBarItem({ state: "token_expiring", tokenExpiresInMinutes: minutesUntilExpiry, }); } else { updateStatusBarItem({ state: "connected", tokenExpiresInMinutes: minutesUntilExpiry > 0 ? minutesUntilExpiry : undefined, }); } } catch (error) { logger.error("Error checking authentication status:", error); updateStatusBarItem({ state: "error", message: "Failed to check status", }); } } export function getStatusBarItem(): vscode.StatusBarItem { return statusBarItem; } export function disposeStatusBarItem(): void { if (statusBarItem) { statusBarItem.dispose(); Logger.getInstance().info("Status bar item disposed"); } } |