src/vs/platform/agentHost/node/agentHostSkillCompletionProvider.ts

122 LOC · 120 covered · 2 uncovered · 30 ranges · 943 concepts · 13 introducers · 502 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- agentHostSkillCompletionProvider.ts ×6
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 { CancellationToken } from '../../../base/common/cancellation.js';
7 > import { Disposable } from '../../../base/common/lifecycle.js';
8 > import { URI } from '../../../base/common/uri.js';
9 > import { SYNCED_CUSTOMIZATION_SCHEME } from '../common/agentHostFileSystemService.js';
10 > import type { IAgent } from '../common/agentService.js';
11 > import { CompletionItem, CompletionItemKind, CompletionsParams } from '../common/state/protocol/commands.js';
12 > import { MessageAttachmentKind } from '../common/state/protocol/state.js';
13 > import { toSkillCompletionAttachmentMeta } from '../common/meta/agentCompletionAttachmentMeta.js';
14 > import { CustomizationType, DirectoryCustomization, PluginCustomization, SkillCustomization } from '../common/state/sessionState.js';
15 > import { CompletionTriggerCharacter, IAgentHostCompletionItemProvider } from './agentHostCompletions.js';
16 > import { extractWhitespaceDelimitedSlashToken, matchesSlashCompletion } from './agentHostSlashCompletion.js';
17 >
18 >
19 > /**
20 > * Generic completion provider that contributes slash completions for skills
21 > * exposed through an agent's global and session-effective customizations.
22 > */
23 > export class AgentHostSkillCompletionProvider extends Disposable implements IAgentHostCompletionItemProvider {
24 >
25 > readonly kinds: ReadonlySet<CompletionItemKind> = new Set([CompletionItemKind.UserMessage]);
26 > readonly triggerCharacters = [CompletionTriggerCharacter.Slash] as const;
27 >
28 > constructor(
29 > private readonly _getAgent: (session: URI | string) => IAgent | undefined, agentHostSkillCompletionProvider.ts ×1
30 > ) {
31 > super();
32 > }
34 > async provideCompletionItems(params: CompletionsParams, token: CancellationToken): Promise<readonly CompletionItem[]> {
35 > const leading = extractWhitespaceDelimitedSlashToken(params.text, params.offset); agentHostSkillCompletionProvider.ts ×4
36 > if (!leading) {
38 > }
40 > const sessionUri = typeof params.channel === 'string' ? URI.parse(params.channel) : params.channel; agentHostSkillCompletionProvider.ts ×4
41 > const agent = this._getAgent(sessionUri);
42 > if (!agent) {
43 return [];
44 }
45 > const candidates = await this._getCandidates(agent, sessionUri); agentHostSkillCompletionProvider.ts ×4
46 > if (token.isCancellationRequested || candidates.length === 0) { agentHostSkillCompletionProvider.ts ×4
48 > }
50 > // `/abc` → typed = 'abc'; empty after just '/' → typed = ''.
51 > const typed = leading.typed;
52 > const skillsSeen = new Set<string>();
53 > return candidates
54 > .filter(skill => {
55 > const uri = skill.uri;
56 > if (matchesSlashCompletion(typed, skill.slashCommandName) && !skillsSeen.has(uri)) {
57 > skillsSeen.add(uri);
58 > return true;
59 > }
62 > .map(skill => ({
63 > insertText: '/' + skill.slashCommandName + ' ',
64 > rangeStart: leading.rangeStart,
65 > rangeEnd: leading.rangeEnd,
66 > attachment: {
67 > type: MessageAttachmentKind.Simple,
68 > label: '/' + skill.slashCommandName,
69 > _meta: toSkillCompletionAttachmentMeta({
70 > uri: skill.uri,
71 > name: skill.name,
72 > displayName: skill.slashCommandName,
73 > description: skill.description,
74 > }),
75 > },
76 > }));
79 > private async _getCandidates(agent: IAgent, session: URI): Promise<readonly SlashCommmandCandidate[]> {
80 > if (!agent.getSessionCustomizations) { agentHostSkillCompletionProvider.ts ×4
82 > }
83 > const customizations = await agent.getSessionCustomizations(session); agentHostSkillCompletionProvider.ts ×2
84 > const result: SlashCommmandCandidate[] = [];
85 > for (const c of customizations) {
86 > if (c.type === CustomizationType.McpServer || !c.enabled || !c.children) { agentHostSkillCompletionProvider.ts ×6
88 > }
89 > for (const child of c.children) { agentHostSkillCompletionProvider.ts ×6
90 > if (child.type === CustomizationType.Skill) {
91 > result.push(this._toSlashCommandCandidate(c, child));
92 > }
93 > }
94 > }
98 > private _toSlashCommandCandidate(container: PluginCustomization | DirectoryCustomization, skill: SkillCustomization): SlashCommmandCandidate {
99 > // see getCanonicalPluginCommandId agentHostSkillCompletionProvider.ts ×6
100 > let slashCommandName = skill.name;
101 > if (container.type === CustomizationType.Plugin && !isSyncedCustomization(container) && skill.name !== container.name) {
102 > slashCommandName = `${container.name}:${skill.name}`; agentHostSkillCompletionProvider.ts ×1
103 > }
105 > slashCommandName: slashCommandName,
106 > name: skill.name,
107 > description: skill.description,
108 > uri: skill.uri,
109 > };
110 > }
112 >
113 > function isSyncedCustomization(container: PluginCustomization): boolean { agentHostSkillCompletionProvider.ts ×1
114 > return container.uri.startsWith(SYNCED_CUSTOMIZATION_SCHEME + ':');
115 > }
117 > interface SlashCommmandCandidate {
118 > readonly slashCommandName: string;
119 > readonly name: string;
120 > readonly description: string | undefined;
121 > readonly uri: string;
122 > }