Skip to content

Commit

Permalink
Refactor CreateSiteCommand and CreateSiteHelper to use structured opt…
Browse files Browse the repository at this point in the history
…ions and improve readability; add CreateSiteTypes for better type management
  • Loading branch information
amitjoshi committed Nov 25, 2024
1 parent 255c97e commit 7653622
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ export class CreateSiteCommand implements Command {
stream.progress(NL2SITE_GENERATING_SITE);
try {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const result = await createSite(
intelligenceAPIEndpointInfo.intelligenceEndpoint,
const result = await createSite({
intelligenceEndpoint: intelligenceAPIEndpointInfo.intelligenceEndpoint,
intelligenceApiToken,
request.prompt,
powerPagesAgentSessionId,
userPrompt: request.prompt,
sessionId: powerPagesAgentSessionId,
stream,
telemetry,
orgID,
envID,
orgId: orgID,
envId: envID,
userId,
extensionContext
);
});
// Process the result

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,26 @@ import { VSCODE_EXTENSION_NL2PAGE_REQUEST, VSCODE_EXTENSION_NL2SITE_REQUEST, VSC
import { EditableFileSystemProvider } from '../../../../utilities/EditableFileSystemProvider';
import { HTML_FILE_EXTENSION, UTF8_ENCODING } from '../../../../constants';
import { EDITABLE_SCHEME } from './CreateSiteConstants';

export const createSite = async (intelligenceEndpoint: string, intelligenceApiToken: string, userPrompt: string, sessionId: string, stream: vscode.ChatResponseStream, telemetry: ITelemetry, orgId: string, envID: string, userId: string, extensionContext: vscode.ExtensionContext) => {
const { siteName, siteDescription, sitePages } = await fetchSiteAndPageData(intelligenceEndpoint, intelligenceApiToken, userPrompt, sessionId, telemetry, stream, orgId, envID, userId);
import { ICreateSiteOptions, IPreviewSitePagesContentOptions } from './CreateSiteTypes';

export const createSite = async (createSiteOptions: ICreateSiteOptions) => {
const {
intelligenceEndpoint,
intelligenceApiToken,
userPrompt,
sessionId,
stream,
telemetry,
orgId,
envId,
userId,
extensionContext
} = createSiteOptions;

const { siteName, siteDescription, sitePages } = await fetchSiteAndPageData(intelligenceEndpoint, intelligenceApiToken, userPrompt, sessionId, telemetry, stream, orgId, envId, userId);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const contentProvider = previewSitePagesContent(siteName, sitePages, stream, extensionContext, telemetry, sessionId, orgId, envID, userId);
const contentProvider = previewSitePagesContent({sitePages, stream, extensionContext, telemetry, sessionId, orgId, envId, userId});

// TODO: Implement the create site button click handler

Expand Down Expand Up @@ -57,16 +71,18 @@ async function fetchSiteAndPageData(intelligenceEndpoint: string, intelligenceAp


function previewSitePagesContent(
siteName: string,
sitePages: any[],
stream: vscode.ChatResponseStream,
extensionContext: vscode.ExtensionContext,
telemetry: ITelemetry,
sessionId: string,
orgId: string,
envId: string,
userId: string
options: IPreviewSitePagesContentOptions
): EditableFileSystemProvider {
const {
sitePages,
stream,
extensionContext,
telemetry,
sessionId,
orgId,
envId,
userId
} = options;
const sitePagesContent: { name: string; content: string }[] = [];
sitePages.forEach((page: any) => {

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

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Unexpected any. Specify a different type

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

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Unexpected any. Specify a different type

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

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Unexpected any. Specify a different type
sitePagesContent.push({ name: page.metadata.pageTitle, content: page.code });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import { ITelemetry } from "../../../../OneDSLoggerTelemetry/telemetry/ITelemetry";
import * as vscode from 'vscode';

export interface ICreateSiteOptions {
intelligenceEndpoint: string;
intelligenceApiToken: string;
userPrompt: string;
sessionId: string;
stream: vscode.ChatResponseStream;
telemetry: ITelemetry;
orgId: string;
envId: string;
userId: string;
extensionContext: vscode.ExtensionContext;
}

export interface IPreviewSitePagesContentOptions {
// siteName: string;
sitePages: any[];

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

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Unexpected any. Specify a different type

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

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Unexpected any. Specify a different type

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

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Unexpected any. Specify a different type
stream: vscode.ChatResponseStream;
extensionContext: vscode.ExtensionContext;
telemetry: ITelemetry;
sessionId: string;
orgId: string;
envId: string;
userId: string;
}

0 comments on commit 7653622

Please sign in to comment.