Skip to content

[#434] CopilotStudio Client WebChat sample failure when cloud is not set#457

Merged
rido-min merged 6 commits intomainfrom
southworks/fix/connection-settings
Jul 16, 2025
Merged

[#434] CopilotStudio Client WebChat sample failure when cloud is not set#457
rido-min merged 6 commits intomainfrom
southworks/fix/connection-settings

Conversation

@sw-joelmut
Copy link
Copy Markdown
Collaborator

Fixes #434

Description

This PR fixes an issue when either cloud or agentType settings are not specified throws an unwanted error instead of using default values.
Additionally, we refactored a bit the ConnectionSettings to 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

  • ConnectionSettings class can be instantiated providing ConnectionOptions, these connection options can be customized to meet public requirements. For example, cloud and copilotAgentType settings 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.
  • Enum definitions has been changed from an incremental number to a string for easier debugging, testing, etc.
  • Some validations have been moved from platform environment to ConnectionSettings and improved error messages.

Testing

The following image shows the WebChat and Console samples working, also using DirectUrl with the scopes.
imagen

@sw-joelmut sw-joelmut requested review from Copilot and rido-min July 15, 2025 15:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 cloud and copilotAgentType in both sample settings and URL construction.
  • Refactors ConnectionSettings to accept either enum values or string keys and centralizes validation logic.
  • Changes PowerPlatformCloud and AgentType enums 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 getCopilotStudioConnectionUrl that verify the default cloud and agentType fallbacks 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.cloud directly to PowerPlatformCloud may allow invalid values to slip through until runtime. You could first treat it as a keyof typeof PowerPlatformCloud, then map to the enum or apply a default for invalid/missing keys to improve clarity.
    cloud: process.env.cloud as PowerPlatformCloud,

Comment thread test-agents/copilotstudio-webchat/settings.js Outdated
Comment thread packages/agents-copilotstudio-client/src/connectionSettings.ts Outdated
rido-min
rido-min previously approved these changes Jul 16, 2025
@rido-min rido-min enabled auto-merge (squash) July 16, 2025 15:33
@rido-min rido-min merged commit 60369fc into main Jul 16, 2025
7 checks passed
@rido-min rido-min deleted the southworks/fix/connection-settings branch July 16, 2025 17:26
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.

CopilotStudio Client WebChat sample failure when cloud is not set

3 participants