Skip to content

Add Zod Activity validation in TurnContext methods#883

Merged
benbrown merged 6 commits intomainfrom
southworks/fix/context-activity-validation
Feb 17, 2026
Merged

Add Zod Activity validation in TurnContext methods#883
benbrown merged 6 commits intomainfrom
southworks/fix/context-activity-validation

Conversation

@sw-joelmut
Copy link
Copy Markdown
Collaborator

Fixes #261

Description

This PR adds the Zod schema validation in TurnContext updateActivity, sendActivity, sendTraceActivity, and sendActivities methods by using the Activity.fromObject utility.

Testing

The following image shows the error shown when passing a wrong activity to updateActivity.
imagen

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 adds Zod schema validation to TurnContext methods by integrating Activity.fromObject() calls, which validates activities against the defined Zod schema. This ensures that malformed activities are caught early with clear validation errors.

Changes:

  • Integrated Activity.fromObject() validation in sendActivities() and updateActivity() methods
  • Refactored variable naming for clarity (e.g., activityObjectactivity, traceActivityObjtraceActivity)
  • Added comprehensive tests for validation in both success and failure scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/agents-hosting/src/turnContext.ts Added Activity.fromObject validation in sendActivities() and updateActivity() methods to validate activities via Zod schema
packages/agents-hosting/test/hosting/adapter/turnContext.test.ts Added test cases to verify validation works correctly for both valid and invalid activities

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/agents-hosting/src/turnContext.ts Outdated
…odes

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread packages/agents-hosting/src/turnContext.ts
@benbrown benbrown enabled auto-merge (squash) February 17, 2026 15:18
@benbrown benbrown merged commit 8e16f68 into main Feb 17, 2026
7 checks passed
@benbrown benbrown deleted the southworks/fix/context-activity-validation branch February 17, 2026 15:20
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.

Failed to call context.updateActivity in onAdaptiveCardInvoke event

3 participants