Skip to content

Commit c59a963

Browse files
committed
Add get_spo_page Language Model Tool for SharePoint. Closes #588
1 parent 90f4da9 commit c59a963

File tree

4 files changed

+108
-4
lines changed

4 files changed

+108
-4
lines changed

package.json

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
]
7474
}
7575
],
76-
"languageModelTools": [
76+
"languageModelTools": [
7777
{
7878
"name": "install_spo_app",
7979
"tags": [
@@ -445,6 +445,45 @@
445445
}
446446
}
447447
},
448+
{
449+
"name": "get_spo_page",
450+
"tags": [
451+
"sharepoint",
452+
"page",
453+
"spfx-toolkit"
454+
],
455+
"toolReferenceName": "SharePointPageGet",
456+
"displayName": "Get a SharePoint Page",
457+
"modelDescription": "Retrieves detailed information about a specific modern SharePoint page. Returns page metadata including title, layout type, canvas content, and status. Use this tool to get details for a specific page by name, OR use the default parameter to get the site's home page. Do not provide both name and default. Do not use this tool to list multiple pages. Requires Microsoft 365 authentication and read permissions on the target site.",
458+
"userDescription": "Gets information about a specific SharePoint page.",
459+
"canBeReferencedInPrompt": true,
460+
"icon": "$(info)",
461+
"inputSchema": {
462+
"type": "object",
463+
"properties": {
464+
"webUrl": {
465+
"type": "string",
466+
"description": "URL of the site where the page is located. This option is required.",
467+
"default": ""
468+
},
469+
"name": {
470+
"type": "string",
471+
"description": "Name of the page to retrieve (e.g., 'home.aspx'). Do not use if 'default' is true.",
472+
"default": ""
473+
},
474+
"default": {
475+
"type": "boolean",
476+
"description": "Set to true to retrieve the site's home page. Do not use if 'name' is specified.",
477+
"default": false
478+
},
479+
"metadataOnly": {
480+
"type": "boolean",
481+
"description": "Set to only retrieve page metadata without canvas content. This option is optional.",
482+
"default": false
483+
}
484+
}
485+
}
486+
},
448487
{
449488
"name": "list_spo_page",
450489
"tags": [
@@ -560,7 +599,7 @@
560599
}
561600
}
562601
}
563-
},
602+
},
564603
{
565604
"name": "upgrade_spfx_project",
566605
"tags": [
@@ -1409,4 +1448,4 @@
14091448
"use-debounce": "10.0.4",
14101449
"rehype-raw": "7.0.0"
14111450
}
1412-
}
1451+
}

src/chat/tools/ChatTools.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
import { lm } from 'vscode';
22
import { Subscription } from '../../models';
33
import { Extension } from '../../services/dataType/Extension';
4-
import { SharePointAppInstall, SharePointAppInstanceList, SharePointAppList, SharePointAppUninstall, SharePointAppUpgrade, SharePointListAdd, SharePointListGet, SharePointListRemove, SharePointPageAdd, SharePointPageList, SharePointSiteAdd, SharePointSiteGet, SharePointSiteRemove } from './spo/index';
4+
import {
5+
SharePointAppInstall,
6+
SharePointAppInstanceList,
7+
SharePointAppList,
8+
SharePointAppUninstall,
9+
SharePointAppUpgrade,
10+
SharePointListAdd,
11+
SharePointListGet,
12+
SharePointListRemove,
13+
SharePointPageAdd,
14+
SharePointPageGet,
15+
SharePointPageList,
16+
SharePointSiteAdd,
17+
SharePointSiteGet,
18+
SharePointSiteRemove
19+
} from './spo/index';
520
import { SharePointFrameworkProjectUpgrade } from './spfx';
621

722

@@ -36,6 +51,9 @@ export class ChatTools {
3651
subscriptions.push(
3752
lm.registerTool('add_spo_page', new SharePointPageAdd())
3853
);
54+
subscriptions.push(
55+
lm.registerTool('get_spo_page', new SharePointPageGet())
56+
);
3957
subscriptions.push(
4058
lm.registerTool('list_spo_page', new SharePointPageList())
4159
);

src/chat/tools/spo/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export * from './list/ListAdd';
77
export * from './list/ListGet';
88
export * from './list/ListRemove';
99
export * from './page/PageAdd';
10+
export * from './page/PageGet';
1011
export * from './page/PageList';
1112
export * from './site/SiteAdd';
1213
export * from './site/SiteGet';

src/chat/tools/spo/page/PageGet.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { CancellationToken, LanguageModelTextPart, LanguageModelTool, LanguageModelToolInvocationOptions, LanguageModelToolInvocationPrepareOptions, LanguageModelToolResult, MarkdownString } from 'vscode';
2+
import { CliExecuter } from '../../../../services/executeWrappers/CliCommandExecuter';
3+
import { validateAuth } from '../utils/ToolAuthValidationUtil';
4+
5+
6+
interface ISharePointPageGetParameters {
7+
webUrl: string;
8+
name?: string;
9+
default?: boolean;
10+
metadataOnly?: boolean;
11+
}
12+
13+
export class SharePointPageGet implements LanguageModelTool<ISharePointPageGetParameters> {
14+
async invoke(
15+
options: LanguageModelToolInvocationOptions<ISharePointPageGetParameters>,
16+
_token: CancellationToken
17+
) {
18+
const params = options.input;
19+
const authValidationResult = await validateAuth();
20+
if (authValidationResult !== true) {
21+
return authValidationResult as LanguageModelToolResult;
22+
}
23+
24+
const result = await CliExecuter.execute('spo page get', 'json', params);
25+
if (result.stderr) {
26+
return new LanguageModelToolResult([new LanguageModelTextPart(`Error: ${result.stderr}`)]);
27+
}
28+
29+
return new LanguageModelToolResult([new LanguageModelTextPart(`Page retrieved successfully ${(result.stdout !== '' ? `\nResult: ${result.stdout}` : '')}`)]);
30+
}
31+
32+
async prepareInvocation(
33+
options: LanguageModelToolInvocationPrepareOptions<ISharePointPageGetParameters>,
34+
_token: CancellationToken
35+
) {
36+
const confirmationMessages = {
37+
title: 'Get a SharePoint Online page',
38+
message: new MarkdownString('Should I get a page with the following parameters?'),
39+
};
40+
41+
return {
42+
invocationMessage: 'Getting SharePoint Online page',
43+
confirmationMessages,
44+
};
45+
}
46+
}

0 commit comments

Comments
 (0)