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

Updated AIB contract with default portal language #959

Conversation

ritikramuka
Copy link
Member

@ritikramuka ritikramuka commented May 20, 2024

This pull request primarily focuses on adding support for default portal language code in the sendApiRequest function and related changes in various files. The changes include adding a new parameter to the sendApiRequest function, fetching the default language code, and passing it to the sendApiRequest function. Additionally, there are changes to telemetry events and utility functions related to finding website YAML files.

The most important changes are:

Addition of default portal language code:

Fetching and passing default language code:

Support for fetching default language code:

  • src/common/copilot/dataverseMetadata.ts: Added a new function getDefaultLanguageCode to fetch the default language code. This function uses various other helper functions added in this file to read website YAML files and fetch language code from API. [1] [2]

Telemetry events:

Utility functions:

Additional changes:

ritikramuka and others added 5 commits May 21, 2024 04:15
The code changes add a new function `findWebsiteYAML` that recursively searches for the `website.yml` file in the given directory and its parent directories. It returns the content of the YAML file if found, or `null` otherwise. The function is used in the `readWebsiteYAML` function to read the `website.yml` file in the workspace folder.

This commit message suggests adding the function to read the website YAML file.
@ritikramuka ritikramuka marked this pull request as ready for review May 20, 2024 23:24
@ritikramuka ritikramuka requested review from a team as code owners May 20, 2024 23:24
src/common/copilot/dataverseMetadata.ts Outdated Show resolved Hide resolved
src/common/copilot/PowerPagesCopilot.ts Outdated Show resolved Hide resolved
src/common/copilot/dataverseMetadata.ts Outdated Show resolved Hide resolved
src/common/copilot/dataverseMetadata.ts Outdated Show resolved Hide resolved
src/common/copilot/IntelligenceApiService.ts Show resolved Hide resolved
src/common/copilot/dataverseMetadata.ts Outdated Show resolved Hide resolved
import { CopilotDataverseMetadataFailureEvent, CopilotDataverseMetadataSuccessEvent, CopilotGetEntityFailureEvent, CopilotYamlParsingFailureEvent } from "./telemetry/telemetryConstants";
import { getEntityMetadata } from "../../web/client/utilities/fileAndEntityUtil";
import { CopilotDataverseMetadataFailureEvent, CopilotDataverseMetadataSuccessEvent, CopilotGetEntityFailureEvent, CopilotGetLanguageCodeFailureEvent, CopilotGetLanguageCodeSuccessEvent, CopilotYamlParsingFailureEvent } from "./telemetry/telemetryConstants";
import { getEntityMetadata, getDefaultLanguageCodeWeb } from "../../web/client/utilities/fileAndEntityUtil";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here - do not introduce dependency on web/client module in common

src/common/copilot/dataverseMetadata.ts Outdated Show resolved Hide resolved
src/common/copilot/dataverseMetadata.ts Outdated Show resolved Hide resolved
src/common/copilot/dataverseMetadata.ts Outdated Show resolved Hide resolved
src/common/utilities/Utils.ts Outdated Show resolved Hide resolved
const websiteYAMLFilePath = path.join(dir, "website.yml");
try {
const diskRead = await import("fs");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we importing this fs here with an await?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

following the pattern used in the code. We had these multiple imports in block level scope.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Evaluate if this is really adding benefit in performance or is there a specific reason - if not lets keep this at start of file like other modules

) {
return null;
}
return await findWebsiteYAML(parentDir, workspaceFolderPath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a great idea to use catch for sceanrio handling

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using try-catch with async-await makes error handling clear and straightforward, enhancing both readability and robustness. Have updated some bits of the flow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to load exception telemetry and do rest of the code handling in a separate code block

@@ -89,6 +90,18 @@ export function getFileName(fsPath: string) {
return fsPath.split(/[\\/]/).pop();
}

export function getDefaultLanguageCodeWeb() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should not be fetching languages on the fly in copilot using these functions - but as part of init call - check the way we are passing orgId, envId etc. That is the right pattern to use. Otherwise you will land in cross module dependency.

ritikramuka and others added 10 commits May 21, 2024 16:18
…EnabledPPACFlag as being a required parameter.
…aders

The code changes in this commit update the fetchLanguageCodeFromAPI function to use the getCommonHeaders function from the AuthenticationProvider service to set the request headers. This change improves code readability and maintainability by centralizing the logic for setting common headers.

Refactor the fetchLanguageCodeFromAPI function to use the getCommonHeaders function for setting request headers.
The code changes in this commit update the findWebsiteYAML function to handle parent directories when the website.yml file is not found in the current directory. It recursively searches for the file in the parent directories until it is found or until the workspace folder path is reached. This change improves the functionality of the findWebsiteYAML function and ensures that the correct YAML file is retrieved.

Update findWebsiteYAML function to handle parent directories when searching for website.yml file.
…d web environments

The code changes in this commit update the getDefaultLanguageCode function in the Language/Utils module. It introduces conditional logic to handle different environments: desktop and web. In the desktop environment, the function fetches the language code from an API based on the organization URL and other parameters. In the web environment, the function calls the getDefaultLanguageCodeWeb function. This change improves the functionality of the getDefaultLanguageCode function and ensures the correct language code is retrieved based on the environment.

Update getDefaultLanguageCode function to handle desktop and web environments.
The code changes in this commit update the `Utils.ts` file to include the `parseYAMLAndFetchKey` function. This function is used to parse YAML content and fetch a specific key from it. The function is added to the existing `Utils.ts` module and can be used in other parts of the codebase. This change improves the modularity and reusability of the code.

Update `Utils.ts` to include `parseYAMLAndFetchKey` function.
@ritikramuka
Copy link
Member Author

as per discussion with Neeraj, dropping plan of using "portal Base Language" to localize co-pilot for now, hence closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants