diff --git a/sema4ai/vscode-client/src/views.ts b/sema4ai/vscode-client/src/views.ts index 4b52f2ef..111f6345 100644 --- a/sema4ai/vscode-client/src/views.ts +++ b/sema4ai/vscode-client/src/views.ts @@ -232,6 +232,11 @@ export function registerViews(context: ExtensionContext) { "treeDataProvider": robotsTreeDataProvider, }); + // Periodic refresh every 60 seconds + setInterval(() => { + robotsTreeDataProvider.updateDatasourceStatuses(); + }, 5 * 1000); + treeViewIdToTreeView.set(TREE_VIEW_SEMA4AI_TASK_PACKAGES_TREE, robotsTree); treeViewIdToTreeDataProvider.set(TREE_VIEW_SEMA4AI_TASK_PACKAGES_TREE, robotsTreeDataProvider); diff --git a/sema4ai/vscode-client/src/viewsRobots.ts b/sema4ai/vscode-client/src/viewsRobots.ts index 9467c0b7..7dd2f665 100644 --- a/sema4ai/vscode-client/src/viewsRobots.ts +++ b/sema4ai/vscode-client/src/viewsRobots.ts @@ -1,13 +1,14 @@ import * as vscode from "vscode"; import { OUTPUT_CHANNEL, logError } from "./channel"; import { uriExists } from "./files"; -import { LocalPackageMetadataInfo, ActionResult, IActionInfo } from "./protocols"; +import { LocalPackageMetadataInfo, ActionResult, IActionInfo, DatasourceInfo, DataSourceState } from "./protocols"; import * as roboCommands from "./robocorpCommands"; import { basename, RobotEntry, RobotEntryType } from "./viewsCommon"; import { getSelectedRobot } from "./viewsSelection"; import { isActionPackage, isAgentPackage } from "./common"; import path = require("path"); -import { getDataSourceCaption, getDataSourceTooltip } from "./robo/actionPackage"; +import { getDataSourceCaption, getDataSourceTooltip, listAllActionPackages } from "./robo/actionPackage"; +import { langServer } from "./extension"; let _globalSentMetric: boolean = false; @@ -43,6 +44,7 @@ export class RobotsTreeDataProvider implements vscode.TreeDataProvider = this._onForceSelectionFromTreeData.event; private lastRoot: RobotEntry[] | undefined = undefined; + globalDataSourceState: Map> = new Map(); fireRootChange() { this._onDidChangeTreeData.fire(null); @@ -52,6 +54,43 @@ export class RobotsTreeDataProvider implements vscode.TreeDataProvider { + let actionResult: ActionResult = await listAllActionPackages(); + if (!actionResult.success) { + return; + } + let localActionPackages: LocalPackageMetadataInfo[] = actionResult.result; + if (localActionPackages.length == 0) { + return; + } + + const dataServerStatus = await vscode.commands.executeCommand("sema4ai-data.dataserver.status"); + if (!dataServerStatus["success"]) { + return; + } + + this.globalDataSourceState.clear(); + + for (const actionPackage of localActionPackages) { + const dataSourceStateResult = (await langServer.sendRequest("computeDataSourceState", { + "action_package_yaml_directory_uri": actionPackage.directory, + "data_server_info": dataServerStatus["data"], + })) as ActionResult; + + if (dataSourceStateResult.success) { + const dataSourcesState: DatasourceInfo[] = dataSourceStateResult.result.required_data_sources; + for (const item of dataSourcesState) { + const innerMap = this.globalDataSourceState.get(actionPackage.filePath) ?? new Map(); + innerMap.set(getDataSourceCaption(item), item); + + this.globalDataSourceState.set(actionPackage.filePath, innerMap); + } + } + } + + this.fireRootChange(); + } + /** * Note that we make sure to only return valid entries here (i.e.: no entries * where RobotEntry.type === RobotEntryType.Error). @@ -521,7 +560,15 @@ export class RobotsTreeDataProvider implements vscode.TreeDataProvider