Skip to content
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

Hook for create site command with nl2page&site #1057

Merged
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,42 @@
/*
* 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 {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async execute(request: any, stream: vscode.ChatResponseStream): Promise<any> {
const { prompt, intelligenceAPIEndpointInfo, intelligenceApiToken, powerPagesAgentSessionId, telemetry } = request;

stream.progress('Generating a new Power Pages site...');
amitjoshi438 marked this conversation as resolved.
Show resolved Hide resolved
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
amitjoshi438 marked this conversation as resolved.
Show resolved Hide resolved
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);

amitjoshi438 marked this conversation as resolved.
Show resolved Hide resolved
return {
siteName,
//websiteId,
siteDescription,
};

} catch (error) {
stream.markdown(`Error: ${(error as Error).message}`);
amitjoshi438 marked this conversation as resolved.
Show resolved Hide resolved
amitjoshi438 marked this conversation as resolved.
Show resolved Hide resolved
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 };
}
Loading