diff --git a/chat-sample/package-lock.json b/chat-sample/package-lock.json index b7f38355..5cda7497 100644 --- a/chat-sample/package-lock.json +++ b/chat-sample/package-lock.json @@ -7,7 +7,6 @@ "": { "name": "chat-sample", "version": "0.1.0", - "hasInstallScript": true, "devDependencies": { "@types/node": "^20.5.9", "@types/vscode": "^1.90.0", diff --git a/chat-sample/package.json b/chat-sample/package.json index a5ed3ab7..02952ae8 100644 --- a/chat-sample/package.json +++ b/chat-sample/package.json @@ -66,11 +66,7 @@ "scripts": { "vscode:prepublish": "npm run compile", "compile": "tsc -p ./", - "watch": "tsc -watch -p ./", - "postinstall": "npm run setupTiktoken", - "setupTiktoken": "run-script-os", - "setupTiktoken:linux:darwin": "cp node_modules/@vscode/prompt-tsx/dist/base/tokenizer/cl100k_base.tiktoken out/", - "setupTiktoken:windows": "copy node_modules\\@vscode\\prompt-tsx\\dist\\base\\tokenizer\\cl100k_base.tiktoken out\\" + "watch": "tsc -watch -p ./" }, "devDependencies": { "@types/node": "^20.5.9", diff --git a/chat-sample/src/extension.ts b/chat-sample/src/extension.ts index 9184233d..d9bbb22d 100644 --- a/chat-sample/src/extension.ts +++ b/chat-sample/src/extension.ts @@ -96,7 +96,7 @@ function registerChatParticipant(context: vscode.ExtensionContext) { const tool = vscode.lm.tools.find(tool => tool.id === part.name); if (!tool) { // BAD tool choice? - continue; + throw new Error('Got invalid tool choice: ' + part.name); } let parameters: any; @@ -109,7 +109,7 @@ function registerChatParticipant(context: vscode.ExtensionContext) { stream.progress(`Calling tool: ${tool.id} with ${part.parameters}`); toolCalls.push({ call: part, - result: vscode.lm.invokeTool(tool.id, { parameters: JSON.parse(part.parameters) }, token), + result: vscode.lm.invokeTool(tool.id, { parameters: JSON.parse(part.parameters), toolInvocationToken: request.toolInvocationToken }, token), tool }); } diff --git a/chat-sample/vscode.proposed.chatParticipantAdditions.d.ts b/chat-sample/vscode.proposed.chatParticipantAdditions.d.ts index 5f489925..1c500f53 100644 --- a/chat-sample/vscode.proposed.chatParticipantAdditions.d.ts +++ b/chat-sample/vscode.proposed.chatParticipantAdditions.d.ts @@ -36,6 +36,11 @@ declare module 'vscode' { constructor(value: string | MarkdownString, vulnerabilities: ChatVulnerability[]); } + export class ChatResponseCodeblockUriPart { + value: Uri; + constructor(value: Uri); + } + /** * Displays a {@link Command command} as a button in the chat response. */ @@ -70,7 +75,7 @@ declare module 'vscode' { constructor(value: Uri, license: string, snippet: string); } - export type ExtendedChatResponsePart = ChatResponsePart | ChatResponseTextEditPart | ChatResponseDetectedParticipantPart | ChatResponseConfirmationPart | ChatResponseCodeCitationPart | ChatResponseReferencePart2; + export type ExtendedChatResponsePart = ChatResponsePart | ChatResponseTextEditPart | ChatResponseDetectedParticipantPart | ChatResponseConfirmationPart | ChatResponseCodeCitationPart | ChatResponseReferencePart2 | ChatResponseMovePart; export class ChatResponseWarningPart { value: MarkdownString; @@ -87,7 +92,7 @@ declare module 'vscode' { /** * The reference target. */ - value: Uri | Location | { variableName: string; value?: Uri | Location }; + value: Uri | Location | { variableName: string; value?: Uri | Location } | string; /** * The icon for the reference. @@ -109,7 +114,7 @@ declare module 'vscode' { * @param value A uri or location * @param iconPath Icon for the reference shown in UI */ - constructor(value: Uri | Location | { variableName: string; value?: Uri | Location }, iconPath?: Uri | ThemeIcon | { + constructor(value: Uri | Location | { variableName: string; value?: Uri | Location } | string, iconPath?: Uri | ThemeIcon | { /** * The icon path for the light theme. */ @@ -121,6 +126,26 @@ declare module 'vscode' { }, options?: { status?: { description: string; kind: ChatResponseReferencePartStatusKind } }); } + export class ChatResponseMovePart { + + readonly uri: Uri; + readonly range: Range; + + constructor(uri: Uri, range: Range); + } + + // Extended to add `SymbolInformation`. Would also be added to `constructor`. + export interface ChatResponseAnchorPart { + /** + * The target of this anchor. + * + * If this is a {@linkcode Uri} or {@linkcode Location}, this is rendered as a normal link. + * + * If this is a {@linkcode SymbolInformation}, this is rendered as a symbol link. + */ + value2: Uri | Location | SymbolInformation; + } + export interface ChatResponseStream { /** @@ -135,6 +160,7 @@ declare module 'vscode' { textEdit(target: Uri, edits: TextEdit | TextEdit[]): void; markdownWithVulnerabilities(value: string | MarkdownString, vulnerabilities: ChatVulnerability[]): void; + codeblockUri(uri: Uri): void; detectedParticipant(participant: string, command?: ChatCommand): void; push(part: ChatResponsePart | ChatResponseTextEditPart | ChatResponseDetectedParticipantPart | ChatResponseWarningPart | ChatResponseProgressPart2): void; @@ -161,7 +187,7 @@ declare module 'vscode' { reference(value: Uri | Location | { variableName: string; value?: Uri | Location }, iconPath?: Uri | ThemeIcon | { light: Uri; dark: Uri }): void; - reference2(value: Uri | Location | { variableName: string; value?: Uri | Location }, iconPath?: Uri | ThemeIcon | { light: Uri; dark: Uri }, options?: { status?: { description: string; kind: ChatResponseReferencePartStatusKind } }): void; + reference2(value: Uri | Location | string | { variableName: string; value?: Uri | Location }, iconPath?: Uri | ThemeIcon | { light: Uri; dark: Uri }, options?: { status?: { description: string; kind: ChatResponseReferencePartStatusKind } }): void; codeCitation(value: Uri, license: string, snippet: string): void; @@ -195,8 +221,37 @@ declare module 'vscode' { documents: ChatDocumentContext[]; } + export interface ChatParticipant { + /** + * Provide a set of variables that can only be used with this participant. + */ + participantVariableProvider?: { provider: ChatParticipantCompletionItemProvider; triggerCharacters: string[] }; + } + + export interface ChatParticipantCompletionItemProvider { + provideCompletionItems(query: string, token: CancellationToken): ProviderResult; + } + + export class ChatCompletionItem { + id: string; + label: string | CompletionItemLabel; + values: ChatVariableValue[]; + fullName?: string; + icon?: ThemeIcon; + insertText?: string; + detail?: string; + documentation?: string | MarkdownString; + command?: Command; + + constructor(id: string, label: string | CompletionItemLabel, values: ChatVariableValue[]); + } + export type ChatExtendedRequestHandler = (request: ChatRequest, context: ChatContext, response: ChatResponseStream, token: CancellationToken) => ProviderResult; + export interface ChatRequest { + toolInvocationToken: ChatParticipantToolToken; + } + export interface ChatResult { nextQuestion?: { prompt: string; @@ -211,19 +266,13 @@ declare module 'vscode' { */ export function createChatParticipant(id: string, handler: ChatExtendedRequestHandler): ChatParticipant; - /** - * Current version of the proposal. Changes whenever backwards-incompatible changes are made. - * If a new feature is added that doesn't break existing code, the version is not incremented. When the extension uses this new feature, it should set its engines.vscode version appropriately. - * But if a change is made to an existing feature that would break existing code, the version should be incremented. - * The chat extension should not activate if it doesn't support the current version. - */ - export const _version: 1 | number; + export function registerChatParticipantDetectionProvider(participantDetectionProvider: ChatParticipantDetectionProvider): Disposable; } export interface ChatParticipantMetadata { participant: string; command?: string; - disambiguation: { categoryName: string; description: string; examples: string[] }[]; + disambiguation: { category: string; description: string; examples: string[] }[]; } export interface ChatParticipantDetectionResult { @@ -231,6 +280,10 @@ declare module 'vscode' { command?: string; } + export interface ChatParticipantDetectionProvider { + provideParticipantDetection(chatRequest: ChatRequest, context: ChatContext, options: { participants?: ChatParticipantMetadata[]; location: ChatLocation }, token: CancellationToken): ProviderResult; + } + /* * User action events */ @@ -257,6 +310,8 @@ declare module 'vscode' { codeBlockIndex: number; totalCharacters: number; newFile?: boolean; + userAction?: string; + codeMapper?: string; } export interface ChatTerminalAction { @@ -299,4 +354,8 @@ declare module 'vscode' { */ readonly name: string; } + + export interface ChatResultFeedback { + readonly unhelpfulReason?: string; + } } diff --git a/chat-sample/vscode.proposed.lmTools.d.ts b/chat-sample/vscode.proposed.lmTools.d.ts index 3fff1acd..e4b045a4 100644 --- a/chat-sample/vscode.proposed.lmTools.d.ts +++ b/chat-sample/vscode.proposed.lmTools.d.ts @@ -103,7 +103,11 @@ declare module 'vscode' { export function invokeTool(id: string, options: LanguageModelToolInvocationOptions, token: CancellationToken): Thenable; } + export type ChatParticipantToolToken = unknown; + export interface LanguageModelToolInvocationOptions { + toolInvocationToken: ChatParticipantToolToken | undefined; + /** * Parameters with which to invoke the tool. */