Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wr/add open agent command #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "extensionHost",
"request": "launch",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"outFiles": ["${workspaceFolder}/lib/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
}
]
Expand Down
21 changes: 19 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@
"categories": [
"Other"
],
"main": "./out/src/index.js",
"main": "./lib/extension.js",
"dependencies": {
"@salesforce/core": "^8.8.0",
"cross-spawn": "^7.0.6",
"semver": "^7.6.3"
},
"devDependencies": {
"@salesforce/dev-config": "^4.3.1",
"@types/cross-spawn": "^6.0.6",
"@commitlint/config-conventional": "^19.5.0",
"@salesforce/dev-config": "^4.3.1",
"@tsconfig/node18": "^18.2.4",
"@types/jest": "^29.5.12",
"@types/node": "^18.11.9",
"@types/semver": "7.5.8",
"@types/shelljs": "^0.8.15",
"@types/vscode": "^1.94.0",
"@typescript-eslint/eslint-plugin": "^8.2.0",
Expand Down Expand Up @@ -88,5 +93,17 @@
"workspaceContains:sfdx-project.json"
],
"contributes": {
"commandPalette": [
{
"command": "salesforcedx-vscode-agents.openAgentInOrg",
"when": "resourceExtname =~ /bot(\\w+|)-meta\\.xml/ || resourceExtname =~ /genAiPlanner-meta\\.xml/"
}
],
"commands": [
{
"command": "salesforcedx-vscode-agents.openAgentInOrg",
"title": "%salesforcedx-vscode-agents.openAgentInOrg%"
}
]
}
}
2 changes: 2 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
{
"salesforcedx-vscode-agents.openAgentInOrg": "Open an Agent in the default Org",
"salesforcedx-vscode-agents.openAgentInOrg.description": "Open an Agent in the default Org Picture description"
}
1 change: 1 addition & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './openAgentInOrg';
25 changes: 25 additions & 0 deletions src/commands/openAgentInOrg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as vscode from 'vscode';
import { Commands } from '../enums/commands';
import { SfProject } from '@salesforce/core';
import * as path from 'path';
import { sync } from 'cross-spawn';

export const registerOpenAgentInOrgCommand = () => {
return vscode.commands.registerCommand(Commands.openAgentInOrg, async () => {
// TODO: maybe an Agent.listLocal() or something similar in the library
const project = SfProject.getInstance();
const defaultPath = project.getDefaultPackage().fullPath;
const agents = (
await vscode.workspace.fs.readDirectory(vscode.Uri.file(path.join(defaultPath, 'main', 'default', 'bots')))
).map(f => f[0]);

// we need to prompt the user which agent to ope
const agentName = await vscode.window.showQuickPick(agents, { title: 'Choose which Agent to open' });

if (!agentName) {
throw new Error('No Agent selected');
}

sync('sf', ['org', 'open', 'agent', '--name', agentName]);
});
};
3 changes: 3 additions & 0 deletions src/enums/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export enum Commands {
openAgentInOrg = 'salesforcedx-vscode-agents.openAgentInOrg'
}
34 changes: 34 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
**/
import * as vscode from 'vscode';
import * as commands from './commands';
import { sync } from 'cross-spawn';
// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
// see "contributes" property in package.json for command list
export async function activate(context: vscode.ExtensionContext) {
try {
/**
* TODO:
* look at E4D CoreExtensionService to see if we need something similar
* decide if we want a hard CLI dependency, ensure it's installed, etc...
*/

const versions = sync('sf', ['version', '--verbose', '--json']);
if (!versions.output.toString().includes('agent')) {
throw new Error('sf CLI + plugin-agent installed required');
}
const disposables: vscode.Disposable[] = [];

// Command Registration
disposables.push(commands.registerOpenAgentInOrgCommand());

context.subscriptions.push(...disposables);
} catch (err: unknown) {
throw new Error(`Failed to initialize: ${(err as Error).message}`);
}
}
2 changes: 1 addition & 1 deletion tsconfig.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"root":["./src/index.ts"],"version":"5.7.2"}
{"root":["./src/extension.ts","./src/index.ts","./src/commands/index.ts","./src/commands/openagentinorg.ts","./src/enums/commands.ts"],"version":"5.7.2"}
Loading