-
Notifications
You must be signed in to change notification settings - Fork 7
feat: change plugin manager to use cpex and remove context forge imports and dependencies #58
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4a178cf
updated from cf to cpex dependency and changed plugin manager APIs ac…
julianstephen f5ec0e4
adapted to work with cpex instead of contextforge
julianstephen a3bf575
refactor: :heavy_minus_sign: Remove nemoguardrails from adapter depen…
julianstephen 4d6be5d
added linting deps to dev
julianstephen 5ef016d
updating build to include plugins build with .toml files replacing re…
julianstephen cae490d
precommit ruff formatting
julianstephen 932ecd0
remove straggling dependencies and add cpex dep to plugins
julianstephen 5660e67
updating tests to use cpex
julianstephen 93f19df
updating tests to use cpex
julianstephen 26c2c0d
Merge branch 'main' into js-cpex
julianstephen ec2eecd
Update Dockerfile
julianstephen 2a35c2b
Update Dockerfile
julianstephen 64582ed
missing model config
julianstephen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,10 +6,13 @@ | |
|
|
||
| # Third-Party | ||
| import pytest | ||
| from enum import Enum | ||
| from typing import Any, Dict, List, Literal, Optional, Union | ||
| from pydantic import BaseModel, Field | ||
|
|
||
| # First-Party | ||
| from mcpgateway.common.models import Message, PromptResult, Role, TextContent | ||
| from mcpgateway.plugins.framework import ( | ||
| # from mcpgateway.common.models import Message, PromptResult, Role, TextContent | ||
| from cpex.framework import ( | ||
| GlobalContext, | ||
| PluginManager, | ||
| PromptHookType, | ||
|
|
@@ -20,6 +23,85 @@ | |
| ) | ||
|
|
||
|
|
||
| ##----- Temporary classes from contextforge-plugins-framework/tests/unit/cpex/fixtures/common/models.py ## | ||
| ## Available at https://github.com/contextforge-org/contextforge-plugins-framework/blob/5769b1bbced23cdc7448bf001aecdbe6a44f22d5/tests/unit/cpex/fixtures/common/models.py | ||
| class Role(str, Enum): | ||
| """Message role in conversations.""" | ||
|
|
||
| ASSISTANT = "assistant" | ||
| USER = "user" | ||
|
|
||
|
|
||
| # Base content types | ||
| class TextContent(BaseModel): | ||
| """Text content for messages (MCP spec-compliant).""" | ||
|
|
||
| type: Literal["text"] | ||
| text: str | ||
| annotations: Optional[Any] = None | ||
| meta: Optional[Dict[str, Any]] = Field(None, alias="_meta") | ||
|
|
||
|
|
||
| class ResourceContents(BaseModel): | ||
| """Base class for resource contents (MCP spec-compliant).""" | ||
|
|
||
| uri: str | ||
| mime_type: Optional[str] = Field(None, alias="mimeType") | ||
| meta: Optional[Dict[str, Any]] = Field(None, alias="_meta") | ||
|
|
||
|
|
||
| # Legacy ResourceContent for backwards compatibility | ||
| class ResourceContent(BaseModel): | ||
| """Resource content that can be embedded (LEGACY - use TextResourceContents or BlobResourceContents).""" | ||
|
|
||
| type: Literal["resource"] | ||
| id: str | ||
| uri: str | ||
| mime_type: Optional[str] = None | ||
| text: Optional[str] = None | ||
| blob: Optional[bytes] = None | ||
|
|
||
|
|
||
| ContentType = Union[TextContent, ResourceContent] | ||
|
|
||
|
|
||
| # Message types | ||
| class Message(BaseModel): | ||
| """A message in a conversation. | ||
|
|
||
| Attributes: | ||
| role (Role): The role of the message sender. | ||
| content (ContentType): The content of the message. | ||
| """ | ||
|
|
||
| role: Role | ||
| content: ContentType | ||
|
|
||
|
|
||
| class PromptMessage(BaseModel): | ||
| """Message in a prompt (MCP spec-compliant).""" | ||
|
|
||
| role: Role | ||
| content: "ContentBlock" # Uses ContentBlock union (includes ResourceLink and EmbeddedResource) | ||
|
|
||
|
|
||
| class PromptResult(BaseModel): | ||
| """Result of rendering a prompt template. | ||
|
|
||
| Attributes: | ||
| messages (List[Message]): The list of messages produced by rendering the prompt. | ||
| description (Optional[str]): An optional description of the rendered result. | ||
| """ | ||
|
|
||
| messages: List[Message] | ||
| description: Optional[str] = None | ||
|
|
||
|
|
||
| # MCP spec-compliant ContentBlock union for prompts and tool results | ||
| # Per spec: ContentBlock can include ResourceLink and EmbeddedResource | ||
| ContentBlock = Union[TextContent] | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module", autouse=True) | ||
| def plugin_manager(): | ||
| """Initialize plugin manager.""" | ||
|
|
@@ -49,7 +131,8 @@ async def test_prompt_post_hook(plugin_manager: PluginManager): | |
| """Test prompt post hook across all registered plugins.""" | ||
| # Customize payload for testing | ||
| message = Message( | ||
| content=TextContent(type="text", text="prompt"), role=Role.USER | ||
| content=TextContent(type="text", text="prompt", _meta={}), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q - is this necessary? can it just default to empty?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember seeing syntax error without it. |
||
| role=Role.USER, | ||
| ) | ||
| prompt_result = PromptResult(messages=[message]) | ||
| payload = PromptPosthookPayload( | ||
|
|
||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.