Skip to content

Commit

Permalink
Hook for create site command with nl2page&site
Browse files Browse the repository at this point in the history
  • Loading branch information
amitjoshi committed Nov 12, 2024
1 parent ff6059d commit 9997664
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ export const NL2SITE_SCENARIO = 'NL2Site';
export const NL2PAGE_GENERATE_NEW_PAGE = 'GenerateNewPage';
export const NL2SITE_GENERATE_NEW_SITE = 'GenerateNewSite';
export const NL2PAGE_SCOPE = 'Page';
export const NL2SITE_REQUEST_FAILED = vscode.l10n.t('Failed to get site content from NL2Site service');
export const NL2PAGE_GENERATING_WEBPAGES = vscode.l10n.t("Generating webpages...");
export const NL2PAGE_RESPONSE_FAILED = 'Failed to get page content from NL2Page service';
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import { Command } from "../../../CommandRegistry";
import * as vscode from 'vscode';
import { createSite } from "./CreateSiteHelper";

export class CreateSiteCommand implements Command {
async execute(request: any, stream: vscode.ChatResponseStream): Promise<any> {

Check warning on line 11 in src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Unexpected any. Specify a different type

Check warning on line 11 in src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Unexpected any. Specify a different type

Check warning on line 11 in src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Unexpected any. Specify a different type

Check warning on line 11 in src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Unexpected any. Specify a different type

Check warning on line 11 in src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 11 in src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Unexpected any. Specify a different type
const { prompt, intelligenceAPIEndpointInfo, intelligenceApiToken, powerPagesAgentSessionId, telemetry } = request;

stream.progress('Generating a new Power Pages site...');
try {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const result = await createSite(
intelligenceAPIEndpointInfo.intelligenceEndpoint,
intelligenceApiToken,
prompt,
powerPagesAgentSessionId,
stream,
telemetry
);
// Process the result

return {
metadata: {
command: 'create-site',
}
};
} catch (error) {
//TODO: Handle error
return {
metadata: {
command: ''
}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import * as vscode from 'vscode';
import { ITelemetry } from '../../../../OneDSLoggerTelemetry/telemetry/ITelemetry';
import { getNL2PageData } from './Nl2PageService';
import { getNL2SiteData } from './Nl2SiteService';
import { NL2SITE_REQUEST_FAILED, NL2PAGE_GENERATING_WEBPAGES, NL2PAGE_RESPONSE_FAILED } from '../../PowerPagesChatParticipantConstants';

export const createSite = async (intelligenceEndpoint: string, intelligenceApiToken: string, userPrompt: string, sessionId: string, stream: vscode.ChatResponseStream, telemetry: ITelemetry) => {
try {
const { siteName, siteDescription } = await fetchSiteAndPageData(intelligenceEndpoint, intelligenceApiToken, userPrompt, sessionId, telemetry, stream);

return {
siteName,
//websiteId,
siteDescription,
};

} catch (error) {
stream.markdown(`Error: ${(error as Error).message}`);
throw error;
}
};

async function fetchSiteAndPageData(intelligenceEndpoint: string, intelligenceApiToken: string, userPrompt: string, sessionId: string, telemetry: ITelemetry, stream: vscode.ChatResponseStream) {
// Call NL2Site service to get initial site content
const { siteName, pages, siteDescription } = await getNL2SiteData(intelligenceEndpoint, intelligenceApiToken, userPrompt, sessionId, telemetry);

if (!siteName) {
stream.markdown(NL2SITE_REQUEST_FAILED);
throw new Error(NL2SITE_REQUEST_FAILED);
}

const sitePagesList = pages.map((page: { pageName: string; }) => page.pageName);

stream.progress(NL2PAGE_GENERATING_WEBPAGES);

// Call NL2Page service to get page content
const sitePages = await getNL2PageData(intelligenceEndpoint, intelligenceApiToken, userPrompt, siteName, sitePagesList, sessionId, telemetry);

if (!sitePages) {
throw new Error(NL2PAGE_RESPONSE_FAILED);
}

return { siteName, sitePagesList, sitePages, siteDescription };
}

0 comments on commit 9997664

Please sign in to comment.