-
Notifications
You must be signed in to change notification settings - Fork 165
Add positron.ai.getAllowedCommands() API for LLM extensions #14913
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,9 @@ | |
| import { Disposable, DisposableMap } from '../../../../base/common/lifecycle.js'; | ||
| import { revive } from '../../../../base/common/marshalling.js'; | ||
| import { URI, UriComponents } from '../../../../base/common/uri.js'; | ||
| import { CommandsRegistry } from '../../../../platform/commands/common/commands.js'; | ||
| import { isIMenuItem, MenuId, MenuRegistry } from '../../../../platform/actions/common/actions.js'; | ||
| import { EditorExtensionsRegistry } from '../../../../editor/browser/editorExtensions.js'; | ||
| import { ChatViewId } from '../../../contrib/chat/browser/chat.js'; | ||
| import { ChatViewPane } from '../../../contrib/chat/browser/widgetHosts/viewPane/chatViewPane.js'; | ||
| import { IChatAgentData, IChatAgentService } from '../../../contrib/chat/common/participants/chatAgents.js'; | ||
|
|
@@ -16,7 +19,7 @@ import { IChatRequestData, IPositronAssistantConfigurationService, IPositronAssi | |
| import { extHostNamedCustomer, IExtHostContext } from '../../../services/extensions/common/extHostCustomers.js'; | ||
| import { IViewsService } from '../../../services/views/common/viewsService.js'; | ||
| import { IChatProgressDto } from '../../common/extHost.protocol.js'; | ||
| import { ExtHostAiFeaturesShape, ExtHostPositronContext, MainPositronContext, MainThreadAiFeaturesShape } from '../../common/positron/extHost.positron.protocol.js'; | ||
| import { ExtHostAiFeaturesShape, ExtHostPositronContext, ISerializedAllowedCommand, MainPositronContext, MainThreadAiFeaturesShape } from '../../common/positron/extHost.positron.protocol.js'; | ||
|
|
||
| @extHostNamedCustomer(MainPositronContext.MainThreadAiFeatures) | ||
| export class MainThreadAiFeatures extends Disposable implements MainThreadAiFeaturesShape { | ||
|
|
@@ -186,4 +189,73 @@ export class MainThreadAiFeatures extends Disposable implements MainThreadAiFeat | |
| async $getEnabledProviders(): Promise<string[]> { | ||
| return this._positronAssistantConfigurationService.getEnabledProviders(); | ||
| } | ||
|
|
||
| /** | ||
| * Return all registered commands with their IDs, descriptions, and parameter metadata. | ||
| * Internal commands (IDs starting with '_') are excluded. | ||
| */ | ||
| async $getAllowedCommands(): Promise<ISerializedAllowedCommand[]> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this, I was thinking we may want to limit the commands we expose from this endpoint to be ones that we also show in the command palette ( Or we allow filtering on |
||
| const allCommands = CommandsRegistry.getCommands(); | ||
| const menuCommands = MenuRegistry.getCommands(); | ||
|
|
||
| // Build title map from command palette menu items — catches MultiCommand/EditorCommand | ||
| // registrations (e.g. undo, redo) that use appendMenuItem instead of addCommand. | ||
| const paletteItemTitles = new Map<string, string>(); | ||
| for (const item of MenuRegistry.getMenuItems(MenuId.CommandPalette)) { | ||
| if (isIMenuItem(item)) { | ||
| const { id, title } = item.command; | ||
| if (title) { | ||
| paletteItemTitles.set(id, typeof title === 'string' ? title : title.value); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Build label map from editor actions (covers undo, redo, cursor commands, etc.) | ||
| const editorActionLabels = new Map<string, string>(); | ||
| for (const action of EditorExtensionsRegistry.getEditorActions()) { | ||
| editorActionLabels.set(action.id, action.label); | ||
| } | ||
|
|
||
| const result: ISerializedAllowedCommand[] = []; | ||
|
|
||
| for (const [id, command] of allCommands) { | ||
| if (id.startsWith('_')) { | ||
| continue; | ||
| } | ||
|
|
||
| const meta = command.metadata; | ||
| const menuCmd = menuCommands.get(id); | ||
|
|
||
| let description: string | undefined; | ||
| if (meta?.description) { | ||
| description = typeof meta.description === 'string' | ||
| ? meta.description | ||
| : meta.description.value; | ||
| } else if (menuCmd) { | ||
| const title = menuCmd.title; | ||
| description = typeof title === 'string' ? title : title.value; | ||
| } else { | ||
| description = paletteItemTitles.get(id) ?? editorActionLabels.get(id); | ||
| } | ||
|
|
||
| const cmdSource = menuCmd?.source; | ||
| const source: ISerializedAllowedCommand['source'] = cmdSource | ||
| ? { type: 'extension', id: cmdSource.id, displayName: cmdSource.title } | ||
| : { type: 'builtin' }; | ||
|
|
||
| result.push({ | ||
| id, | ||
| description, | ||
| args: meta?.args?.map(a => ({ | ||
| name: a.name, | ||
| description: a.description, | ||
| isOptional: a.isOptional, | ||
| })), | ||
| returns: meta?.returns, | ||
| source, | ||
| }); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 ooh, it would be great if we could filter on extension vs builtin commands in the future (I don't think we'll need it for the curated Assistant experience).