Skip to content

Add pluggable activity context#288

Merged
heyitsaamir merged 5 commits into
mainfrom
aamirj/plugin
Aug 21, 2025
Merged

Add pluggable activity context#288
heyitsaamir merged 5 commits into
mainfrom
aamirj/plugin

Conversation

@heyitsaamir

@heyitsaamir heyitsaamir commented Aug 4, 2025

Copy link
Copy Markdown
Collaborator

This PR introduces the ability for plugins to add typed values to the activity context. It does this by adding a dedicated buildActivityContext function that gets called in app.process. Then via a bunch of generics plumbing we merge the plugin's context values with the default ones.

We can use this to separate graph out into other packages, but keep the contextual objects for the activity-handlers unchanged (aka. appGraph, and userGraph will still be available). However, graph object on app would most likely be part of the the GraphPlugin - (maybe we make that accessible via a new app.getPlugin('graph') method?)

Here's a mini demo:

Screen.Recording.2025-08-04.at.8.35.09.AM.mov

PR Dependency Tree

This tree was auto-generated by Charcoal

@heyitsaamir
heyitsaamir requested a review from Copilot August 5, 2025 13:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 introduces a pluggable activity context system that allows plugins to add typed values to the activity context. The implementation adds a new buildActivityContext method to the plugin interface and updates all activity context types to support generics for plugin-provided context values.

Key changes:

  • Adds buildActivityContext method to the plugin interface for injecting typed context values
  • Updates all activity context interfaces and route types to accept generic context parameters
  • Implements context merging logic in the app processing pipeline

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/apps/src/types/plugin/plugin.ts Adds generic type parameters and buildActivityContext method to plugin interface
packages/apps/src/contexts/activity.ts Updates activity context interfaces to support generic plugin context types
packages/apps/src/app.process.ts Implements plugin context building and merging in activity processing
packages/apps/src/routes/*.ts Updates all route type definitions to support generic context parameters
packages/apps/src/router.ts Updates router class to support typed plugin contexts
packages/apps/src/app.ts Updates app class to use typed plugin contexts in router
packages/apps/src/types/app-routing.ts Adds utility type for extracting plugin context types

Comment thread packages/apps/src/app.process.ts Outdated
Comment thread packages/apps/src/app.process.ts Outdated
Comment thread packages/apps/src/types/plugin/plugin.ts Outdated
Comment thread packages/apps/src/types/plugin/plugin.ts Outdated
Comment thread packages/apps/src/types/app-routing.ts Outdated
Comment thread packages/apps/src/routes/index.ts
Comment thread packages/apps/src/contexts/activity.ts

@aacebo aacebo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

left questions, this is a good first draft let me know when its ready for another review!

@heyitsaamir
heyitsaamir marked this pull request as ready for review August 8, 2025 06:22
@heyitsaamir

Copy link
Copy Markdown
Collaborator Author

left questions, this is a good first draft let me know when its ready for another review!

Updated it with your suggestions @aacebo . Take a look!

@heyitsaamir
heyitsaamir merged commit e078b0e into main Aug 21, 2025
5 checks passed
@heyitsaamir
heyitsaamir deleted the aamirj/plugin branch August 21, 2025 21:35
@joshkaplinsky

joshkaplinsky commented Dec 5, 2025

Copy link
Copy Markdown

Does this behavior still work? I'm unable to pass the additional context from onActivity in a plugin down to the activity handler via context parameter (missing the typing as well). Appears that potentially the additional value(s) aren't included in the IActivityContext from the call to .toInterface() here:

const res = await routes[i](ctx || context.toInterface());

@heyitsaamir

Copy link
Copy Markdown
Collaborator Author

Does this behavior still work? I'm unable to pass the additional context from onActivity in a plugin down to the activity handler via context parameter (missing the typing as well). Appears that potentially the additional value(s) aren't included in the IActivityContext from the call to .toInterface() here:

const res = await routes[i](ctx || context.toInterface());

I think you're right. This needs a test. Will prioritize this fix.

BTW, what's the use case you're looking for with this?

@joshkaplinsky

joshkaplinsky commented Dec 8, 2025

Copy link
Copy Markdown

I think you're right. This needs a test. Will prioritize this fix.

Thanks! Appreciate the quick response.

BTW, what's the use case you're looking for with this?

We're wrapping the Teams SDK in our own abstraction, being built as part of a larger system. This plugin approach would enable us to enrich inbound requests with additional, domain-specific context that can propagate through the remainder of the route chain. Think, for example, aadObjectId correlation to our own internal user system, so the various event handles only need to focus on business logic.

heyitsaamir added a commit that referenced this pull request Jan 22, 2026
This PR #288 introduces the
ability for plugins to provide extra context.
Unfortunately, the PR was incomplete, and needed tests.

This PR adds tests, and fixes the issues with actually plumbing that
value through to the context.
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.

5 participants