[#434] CopilotStudio Client WebChat sample failure when cloud is not set#457
Merged
[#434] CopilotStudio Client WebChat sample failure when cloud is not set#457
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that cloud and copilotAgentType default correctly when not specified, refactors the ConnectionSettings implementation for flexible input handling, and updates enum values to strings.
- Introduces default fallback for
cloudandcopilotAgentTypein both sample settings and URL construction. - Refactors
ConnectionSettingsto accept either enum values or string keys and centralizes validation logic. - Changes
PowerPlatformCloudandAgentTypeenums from numeric to string values for easier debugging.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test-agents/copilotstudio-webchat/settings.js | Migrate sample settings to use ConnectionSettings with null defaults instead of empty strings |
| packages/agents-copilotstudio-client/src/powerPlatformEnvironment.ts | Simplify defaulting logic and validations for cloud, custom cloud URL, and agent type |
| packages/agents-copilotstudio-client/src/powerPlatformCloud.ts | Convert PowerPlatformCloud enum values from numbers to strings |
| packages/agents-copilotstudio-client/src/connectionSettings.ts | Refactor ConnectionSettings class to accept flexible input types and enforce enum validations |
| packages/agents-copilotstudio-client/src/agentType.ts | Convert AgentType enum values from numbers to strings |
Comments suppressed due to low confidence (2)
packages/agents-copilotstudio-client/src/powerPlatformEnvironment.ts:42
- Consider adding unit tests for
getCopilotStudioConnectionUrlthat verify the defaultcloudandagentTypefallbacks when those settings are undefined or null, ensuring this behavior remains stable.
const cloudSetting = settings.cloud ?? PowerPlatformCloud.Prod
packages/agents-copilotstudio-client/src/connectionSettings.ts:89
- [nitpick] Casting
process.env.clouddirectly toPowerPlatformCloudmay allow invalid values to slip through until runtime. You could first treat it as akeyof typeof PowerPlatformCloud, then map to the enum or apply a default for invalid/missing keys to improve clarity.
cloud: process.env.cloud as PowerPlatformCloud,
rido-min
previously approved these changes
Jul 16, 2025
…ings' into southworks/fix/connection-settings
rido-min
approved these changes
Jul 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #434
Description
This PR fixes an issue when either
cloudoragentTypesettings are not specified throws an unwanted error instead of using default values.Additionally, we refactored a bit the
ConnectionSettingsto better handle these two properties, the enum definitions, and the settings validations, fixing a small bug condition with custom cloud when cloud is Other.Additional changes
cloudandcopilotAgentTypesettings can be provided either by the Enum or the string value of the Enum, allowing flexibility, and underneath, ConnectionSettings will map the string to the Enum value.Testing
The following image shows the WebChat and Console samples working, also using DirectUrl with the scopes.
