Skip to content

Commit 67c9d9f

Browse files
authored
utils: fix github copilot sdk not found error (#2257)
* initial * small change * update version * oops * requested changes
1 parent 094f711 commit 67c9d9f

File tree

9 files changed

+103
-45
lines changed

9 files changed

+103
-45
lines changed

utils/copilot.d.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import type * as vscode from 'vscode';
7+
import type * as vscodeTypes from 'vscode';
8+
import type { Event, MessageItem, Uri, WorkspaceFolder } from 'vscode';
9+
import type { AzExtInputBoxOptions, AzExtOpenDialogOptions, AzExtWorkspaceFolderPickOptions, IAzureMessageOptions, IAzureQuickPickItem, IAzureQuickPickOptions, IAzureUserInput, IActionContext, PromptResult } from './index';
10+
11+
/**
12+
* Wrapper class of several `vscode.window` methods that handle user input.
13+
* This class is meant to only be used for copilot input scenerios
14+
*/
15+
export declare class CopilotUserInput implements IAzureUserInput {
16+
constructor(vscode: typeof import('vscode'), relevantContext?: string, getLoadingView?: () => vscodeTypes.WebviewPanel | undefined);
17+
onDidFinishPrompt: Event<PromptResult>;
18+
showQuickPick<T extends IAzureQuickPickItem>(items: T[] | Thenable<T[]>, options: IAzureQuickPickOptions & { canPickMany: true; }): Promise<T[]>;
19+
showQuickPick<T extends IAzureQuickPickItem>(items: T[] | Thenable<T[]>, options: IAzureQuickPickOptions): Promise<T>;
20+
showInputBox(options: AzExtInputBoxOptions): Promise<string>;
21+
showWarningMessage<T extends MessageItem>(message: string, ...items: T[]): Promise<T>;
22+
showWarningMessage<T extends MessageItem>(message: string, options: IAzureMessageOptions, ...items: T[]): Promise<T>;
23+
showOpenDialog(options: AzExtOpenDialogOptions): Promise<Uri[]>;
24+
showWorkspaceFolderPick(options: AzExtWorkspaceFolderPickOptions): Promise<WorkspaceFolder>;
25+
}
26+
27+
/**
28+
* Disposes of copilot session created by `CopilotUserInput`
29+
* Should be called after commands using `CopilotUserInput` to prevent any lingering copilot sessions
30+
*/
31+
export function disposeCopilotSession(): Promise<void>;
32+
33+
/**
34+
* When setting the ui to `CopilotUserInput`, call this function so that the context can be properly identified
35+
* @param context The context to mark as using `CopilotUserInput`
36+
*/
37+
export function markAsCopilotUserInput(context: IActionContext, relevantContext?: string, getLoadingView?: () => vscode.WebviewPanel | undefined): void;
38+
39+
export function createPrimaryPromptToGetSingleQuickPickInput(picks: string[], placeholder?: string): string;
40+
export function createPrimaryPromptToGetPickManyQuickPickInput(picks: string[], relevantContext?: string): string;
41+
export function createPrimaryPromptForInputBox(inputQuestion: string, relevantContext?: string): string;
42+
export function createPrimaryPromptForWarningMessage(message: string, items: MessageItem[]): string;
43+
export function createPrimaryPromptForWorkspaceFolderPick(folders: readonly vscode.WorkspaceFolder[] | undefined, relevantContext?: string): string;
44+
export function doGithubCopilotInteraction(primaryPrompt: string, relevantContext?: string): Promise<string>;
45+
export function getCopilotSession(relevantContext?: string): Promise<unknown>;

utils/index.d.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,23 +1026,6 @@ export declare class AzExtUserInput implements IAzureUserInput {
10261026
showWorkspaceFolderPick(options: AzExtWorkspaceFolderPickOptions): Promise<WorkspaceFolder>;
10271027
}
10281028

1029-
/**
1030-
* Wrapper class of several `vscode.window` methods that handle user input.
1031-
* This class is meant to only be used for copilot input scenerios
1032-
*/
1033-
1034-
export declare class CopilotUserInput implements IAzureUserInput {
1035-
constructor(vscode: typeof import('vscode'), relevantContext?: string, getLoadingView?: () => vscodeTypes.WebviewPanel | undefined);
1036-
onDidFinishPrompt: Event<PromptResult>;
1037-
showQuickPick<T extends QuickPickItem>(items: T[] | Thenable<T[]>, options: IAzureQuickPickOptions & { canPickMany: true; }): Promise<T[]>;
1038-
showQuickPick<T extends QuickPickItem>(items: T[] | Thenable<T[]>, options: IAzureQuickPickOptions): Promise<T>;
1039-
showInputBox(options: AzExtInputBoxOptions): Promise<string>;
1040-
showWarningMessage<T extends MessageItem>(message: string, ...items: T[]): Promise<T>;
1041-
showWarningMessage<T extends MessageItem>(message: string, options: IAzureMessageOptions, ...items: T[]): Promise<T>;
1042-
showOpenDialog(options: AzExtOpenDialogOptions): Promise<Uri[]>;
1043-
showWorkspaceFolderPick(options: AzExtWorkspaceFolderPickOptions): Promise<WorkspaceFolder>;
1044-
}
1045-
10461029
/**
10471030
* Specifies the sort priority of a quick pick item
10481031
*/
@@ -2929,22 +2912,11 @@ export declare function runWithInputs<T>(callbackId: string, inputs: (string | R
29292912
*/
29302913
export declare function testGlobalSetup(): UIExtensionVariables;
29312914

2932-
/**
2933-
* Disposes of copilot session created by `CopilotUserInput`
2934-
* Should be called after commands using `CopilotUserInput` to prevent any lingering copilot sessions
2935-
*/
2936-
export function disposeCopilotSession(): Promise<void>;
2937-
29382915
/**
29392916
* Checks if the context is using `CopilotUserInput`
29402917
*/
29412918
export function isCopilotUserInput(context: IActionContext): boolean;
29422919

2943-
/**
2944-
* When setting the ui to `CopilotUserInput`, call this function so that the context can be properly identified
2945-
* @param context The context to mark as using `CopilotUserInput`
2946-
*/
2947-
export function markAsCopilotUserInput(context: IActionContext, relevantContext?: string, getLoadingView?: () => vscode.WebviewPanel | undefined): void;
29482920
/**
29492921
* Checks if the Copilot CLI is installed, and if not, prompts the user to install it.
29502922
* If the user agrees to install it, this will attempt to install the Copilot CLI automatically.

utils/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

utils/package.json

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@microsoft/vscode-azext-utils",
33
"author": "Microsoft Corporation",
4-
"version": "4.0.6",
4+
"version": "4.0.7",
55
"description": "Common UI tools for developing Azure extensions for VS Code",
66
"tags": [
77
"azure",
@@ -14,6 +14,37 @@
1414
"module": "dist/esm/src/index.js",
1515
"main": "dist/cjs/src/index.js",
1616
"types": "index.d.ts",
17+
"exports": {
18+
".": {
19+
"types": "./index.d.ts",
20+
"import": "./dist/esm/src/index.js",
21+
"require": "./dist/cjs/src/index.js"
22+
},
23+
"./copilot": {
24+
"types": "./copilot.d.ts",
25+
"import": "./dist/esm/src/copilotEntry.js",
26+
"require": "./dist/cjs/src/copilotEntry.js"
27+
},
28+
"./activity": {
29+
"types": "./activity.d.ts"
30+
},
31+
"./hostapi": {
32+
"types": "./hostapi.d.ts"
33+
}
34+
},
35+
"typesVersions": {
36+
"*": {
37+
"copilot": [
38+
"copilot.d.ts"
39+
],
40+
"activity": [
41+
"activity.d.ts"
42+
],
43+
"hostapi": [
44+
"hostapi.d.ts"
45+
]
46+
}
47+
},
1748
"license": "MIT",
1849
"repository": {
1950
"type": "git",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
export const copilotUserInputCanaryKey = '_copilotUserInput';

utils/src/copilotEntry.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
export * from './copilot/copilot';
7+
export { CopilotUserInput, markAsCopilotUserInput } from './userInput/CopilotUserInput';

utils/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export { createAzExtLogOutputChannel, createAzExtOutputChannel } from './AzExtOu
99
export * from './AzExtTreeFileSystem';
1010
export * from './callWithTelemetryAndErrorHandling';
1111
export { activityErrorContext, activityFailContext, activityFailIcon, activityInfoContext, activityInfoIcon, activityProgressContext, activityProgressIcon, activitySuccessContext, activitySuccessIcon } from './constants';
12-
export * from './copilot/copilot';
1312
export * from './copilot/installCopilotCli';
1413
export * from './createApiProvider';
1514
export { createExperimentationService } from './createExperimentationService';
@@ -53,7 +52,6 @@ export * from './tree/v2/createGenericElement';
5352
export * from './tree/v2/TreeElementStateManager';
5453
export * from './userInput/AzExtUserInput';
5554
export * from './userInput/AzExtUserInputWithInputQueue';
56-
export * from './userInput/CopilotUserInput';
5755
export * from './utils/activityUtils';
5856
export * from './utils/AzExtFsExtra';
5957
export * from './utils/AzureResourceIdTelemetry';

utils/src/userInput/CopilotUserInput.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import type * as vscodeTypes from 'vscode';
7-
import { workspace } from 'vscode';
7+
import * as vscode from 'vscode';
88
import * as types from '../../index';
9+
import { type IActionContext } from '../../index';
910
import { createPrimaryPromptForInputBox, createPrimaryPromptForWarningMessage, createPrimaryPromptForWorkspaceFolderPick, createPrimaryPromptToGetPickManyQuickPickInput, createPrimaryPromptToGetSingleQuickPickInput, doGithubCopilotInteraction } from '../copilot/copilot';
11+
import { copilotUserInputCanaryKey } from '../copilot/copilotConstants';
1012
import { InvalidCopilotResponseError } from '../errors';
1113

14+
export function markAsCopilotUserInput(context: IActionContext, relevantContext?: string, getLoadingView?: () => vscode.WebviewPanel | undefined): void {
15+
context.ui = new CopilotUserInput(vscode, relevantContext, getLoadingView);
16+
(context as unknown as Record<string, unknown>)[copilotUserInputCanaryKey] = true;
17+
}
18+
1219
export class CopilotUserInput implements types.IAzureUserInput {
1320
private readonly _vscode: typeof vscodeTypes;
1421
private readonly _onDidFinishPromptEmitter: vscodeTypes.EventEmitter<types.PromptResult>;
@@ -46,9 +53,9 @@ export class CopilotUserInput implements types.IAzureUserInput {
4653
}
4754

4855
public async showWorkspaceFolderPick(_options: types.AzExtWorkspaceFolderPickOptions,): Promise<vscodeTypes.WorkspaceFolder> {
49-
const primaryPrompt: string = createPrimaryPromptForWorkspaceFolderPick(workspace.workspaceFolders, this._relevantContext);
56+
const primaryPrompt: string = createPrimaryPromptForWorkspaceFolderPick(vscode.workspace.workspaceFolders, this._relevantContext);
5057
const response = await doGithubCopilotInteraction(primaryPrompt, this._relevantContext);
51-
const pick = (workspace.workspaceFolders ?? []).find(folder => {
58+
const pick = (vscode.workspace.workspaceFolders ?? []).find(folder => {
5259
return folder.name === response;
5360
});
5461

utils/src/utils/copilotUtils.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as vscode from "vscode";
76
import { IActionContext } from "../..";
8-
import { CopilotUserInput } from "../userInput/CopilotUserInput";
9-
10-
const copilotUserInputCanaryKey = '_copilotUserInput';
7+
import { copilotUserInputCanaryKey } from "../copilot/copilotConstants";
118

129
export function isCopilotUserInput(context: IActionContext): boolean {
1310
return !!(context as unknown as Record<string, unknown>)[copilotUserInputCanaryKey];
1411
}
15-
16-
export function markAsCopilotUserInput(context: IActionContext, relevantContext?: string, getLoadingView?: () => vscode.WebviewPanel | undefined): void {
17-
context.ui = new CopilotUserInput(vscode, relevantContext, getLoadingView);
18-
(context as unknown as Record<string, unknown>)[copilotUserInputCanaryKey] = true;
19-
}

0 commit comments

Comments
 (0)