Skip to content

Conversation

h3xxit
Copy link
Member

@h3xxit h3xxit commented Sep 21, 2025

Summary by cubic

Adds selective authentication for OpenAPI-generated tools via a new auth_tools field and introduces an in-memory embeddings tool search plugin for semantic matching.

  • New Features

    • Add auth_tools to HttpCallTemplate and TextCallTemplate to apply auth only to endpoints requiring it per OpenAPI; public endpoints stay unauthenticated.
    • OpenApiConverter uses auth_tools when compatible with the spec’s security scheme, otherwise falls back to placeholders; supports API key, Basic, OAuth2.
    • Proper serialization/validation for auth and auth_tools via AuthSerializer; README examples added.
    • New in_mem_embeddings tool search plugin:
      • In-memory semantic search with optional sentence-transformers/torch, with a simple fallback if not installed.
      • Embedding cache, configurable model_name, similarity threshold, and worker pool.
      • Registered via utcp.plugins entry point; comprehensive tests and docs included.
  • Bug Fixes

    • Fixed aiohttp test fixtures by injecting app into aiohttp_client to resolve pytest dependency issues.

Thuraabtech and others added 3 commits September 21, 2025 11:00
* Added embedding search feature for utcp 1.0

* Update plugins/tool_search/embedding/pyproject.toml

Co-authored-by: Copilot <[email protected]>

* Update plugins/tool_search/embedding/README.md

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* To be resolve

* folder structure to be resolved

* Correct folder placement done.

* Description for values accepted by model_name

* Resolved cubic suggestions

* Update plugins/tool_search/in_mem_embeddings/tests/test_in_mem_embeddings_search.py

Co-authored-by: Copilot <[email protected]>

* No change in core for implementing a plugin

---------

Co-authored-by: Razvan Radulescu <[email protected]>
Co-authored-by: Salman Mohammed <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
* Add auth_tools field for selective authentication in OpenAPI tool generation

- Add auth_tools field to HttpCallTemplate for tool-specific authentication
- Implement compatibility checking between OpenAPI security schemes and auth_tools
- Apply real credentials when compatible, use placeholders when incompatible
- Preserve existing behavior for public endpoints (no auth required)
- Add comprehensive test coverage for all authentication scenarios
- Update documentation with auth_tools examples and usage
- Maintain full backward compatibility

* Update implementation files and documentation for auth_tools feature

- Update HttpCallTemplate, HttpCommunicationProtocol, and OpenApiConverter
- Add auth_tools examples to README.md
- Update existing tests for new auth_tools parameter
- Add integration test for auth_tools field functionality

* fix: resolve pytest fixture dependency issue in HTTP tests

- Fix aiohttp_client fixture usage by properly injecting app dependency
- Ensure all test fixtures receive required parameters correctly
- All 153 tests now pass without fixture conflicts

* feat: add auth_tools support to text plugin

- Add auth_tools field to TextCallTemplate for OpenAPI-generated tools
- Pass auth_tools to OpenApiConverter when processing local OpenAPI specs
- Update documentation to reflect new authentication capabilities
- Add test coverage for auth_tools functionality
- Maintains backward compatibility (auth_tools is optional)

This allows text plugin to apply authentication to tools generated from
local OpenAPI specifications, enabling secure API calls while keeping
file access authentication-free.

* fix: add proper serialization/validation for auth and auth_tools fields

- Add field_serializer and field_validator for auth_tools in TextCallTemplate
- Add field_serializer and field_validator for both auth and auth_tools in HttpCallTemplate
- Use AuthSerializer.validate_dict() for proper dict-to-Auth conversion
- Add comprehensive test coverage for auth_tools serialization
- Ensures dict configurations preserve all critical authentication fields
- All 155 tests pass with proper field validation

* Update README.md

---------

Co-authored-by: Razvan Radulescu <[email protected]>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

10 issues found across 19 files

Prompt for AI agents (all 10 issues)

Understand the root cause of the following 10 issues and fix them.


<file name="plugins/tool_search/in_mem_embeddings/tests/test_plugin.py">

<violation number="1" location="plugins/tool_search/in_mem_embeddings/tests/test_plugin.py:106">
Incorrect exit code logic: script exits with code 1 on success because test_plugin returns None.</violation>
</file>

<file name="plugins/tool_search/in_mem_embeddings/tests/test_performance.py">

<violation number="1" location="plugins/tool_search/in_mem_embeddings/tests/test_performance.py:11">
Incorrect plugin src path; points to non-existent tests/src and will break imports.</violation>

<violation number="2" location="plugins/tool_search/in_mem_embeddings/tests/test_performance.py:12">
Incorrect core src path; does not reach repo root, causing import failures for utcp.*</violation>

<violation number="3" location="plugins/tool_search/in_mem_embeddings/tests/test_performance.py:103">
Incorrect exit logic; script exits with 1 even when test passes because the async test returns None.</violation>
</file>

<file name="plugins/communication_protocols/http/src/utcp_http/openapi_converter.py">

<violation number="1" location="plugins/communication_protocols/http/src/utcp_http/openapi_converter.py:230">
OAuth2 compatibility check is too permissive; token_url (at minimum) should be compared before accepting auth_tools.</violation>
</file>

<file name="README.md">

<violation number="1" location="README.md:483">
auth_tools is not applicable to Text call templates; this may mislead users or cause validation issues. Remove this block from the Text example.</violation>
</file>

<file name="plugins/tool_search/in_mem_embeddings/src/utcp_in_mem_embeddings/in_mem_embeddings_search.py">

<violation number="1" location="plugins/tool_search/in_mem_embeddings/src/utcp_in_mem_embeddings/in_mem_embeddings_search.py:87">
Fixed 384-dim zero vector for empty text can mismatch model embedding dimensions, producing erroneous 0 similarities.</violation>
</file>

<file name="plugins/communication_protocols/http/src/utcp_http/http_call_template.py">

<violation number="1" location="plugins/communication_protocols/http/src/utcp_http/http_call_template.py:111">
Redundant serializer for &#39;auth&#39; duplicates base CallTemplate logic; prefer relying on the base serializer to avoid duplication.</violation>

<violation number="2" location="plugins/communication_protocols/http/src/utcp_http/http_call_template.py:118">
Redundant validator for &#39;auth&#39; duplicates base CallTemplate logic; remove or rely on base to keep a single source of truth.</violation>
</file>

<file name="plugins/communication_protocols/http/tests/test_openapi_converter.py">

<violation number="1" location="plugins/communication_protocols/http/tests/test_openapi_converter.py:40">
Avoid live network calls in tests; mock or fixture the OpenAPI spec to improve test reliability.</violation>
</file>

React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.


if __name__ == "__main__":
success = asyncio.run(test_plugin())
sys.exit(0 if success else 1)
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Sep 21, 2025

Choose a reason for hiding this comment

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

Incorrect exit code logic: script exits with code 1 on success because test_plugin returns None.

Prompt for AI agents
Address the following comment on plugins/tool_search/in_mem_embeddings/tests/test_plugin.py at line 106:

<comment>Incorrect exit code logic: script exits with code 1 on success because test_plugin returns None.</comment>

<file context>
@@ -0,0 +1,106 @@
+
+if __name__ == &quot;__main__&quot;:
+    success = asyncio.run(test_plugin())
+    sys.exit(0 if success else 1)
</file context>

✅ Addressed in f378e67


if __name__ == "__main__":
success = asyncio.run(test_performance())
sys.exit(0 if success else 1)
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Sep 21, 2025

Choose a reason for hiding this comment

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

Incorrect exit logic; script exits with 1 even when test passes because the async test returns None.

Prompt for AI agents
Address the following comment on plugins/tool_search/in_mem_embeddings/tests/test_performance.py at line 103:

<comment>Incorrect exit logic; script exits with 1 even when test passes because the async test returns None.</comment>

<file context>
@@ -0,0 +1,103 @@
+
+if __name__ == &quot;__main__&quot;:
+    success = asyncio.run(test_performance())
+    sys.exit(0 if success else 1)
</file context>

✅ Addressed in f378e67

async def _get_text_embedding(self, text: str) -> np.ndarray:
"""Generate embedding for given text."""
if not text:
return np.zeros(384) # Default dimension for all-MiniLM-L6-v2
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Sep 21, 2025

Choose a reason for hiding this comment

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

Fixed 384-dim zero vector for empty text can mismatch model embedding dimensions, producing erroneous 0 similarities.

Prompt for AI agents
Address the following comment on plugins/tool_search/in_mem_embeddings/src/utcp_in_mem_embeddings/in_mem_embeddings_search.py at line 87:

<comment>Fixed 384-dim zero vector for empty text can mismatch model embedding dimensions, producing erroneous 0 similarities.</comment>

<file context>
@@ -0,0 +1,241 @@
+    async def _get_text_embedding(self, text: str) -&gt; np.ndarray:
+        &quot;&quot;&quot;Generate embedding for given text.&quot;&quot;&quot;
+        if not text:
+            return np.zeros(384)  # Default dimension for all-MiniLM-L6-v2
+            
+        if self._embedding_model is None:
</file context>
Fix with Cubic

return None
return AuthSerializer().to_dict(auth)

@field_validator('auth', mode='before')
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Sep 21, 2025

Choose a reason for hiding this comment

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

Redundant validator for 'auth' duplicates base CallTemplate logic; remove or rely on base to keep a single source of truth.

Prompt for AI agents
Address the following comment on plugins/communication_protocols/http/src/utcp_http/http_call_template.py at line 118:

<comment>Redundant validator for &#39;auth&#39; duplicates base CallTemplate logic; remove or rely on base to keep a single source of truth.</comment>

<file context>
@@ -96,10 +103,49 @@ class HttpCallTemplate(CallTemplate):
+            return None
+        return AuthSerializer().to_dict(auth)
+
+    @field_validator(&#39;auth&#39;, mode=&#39;before&#39;)
+    @classmethod
+    def validate_auth(cls, v: Any) -&gt; Optional[Auth]:
</file context>

✅ Addressed in f378e67

body_field: Optional[str] = Field(default="body", description="The name of the single input field to be sent as the request body.")
header_fields: Optional[List[str]] = Field(default=None, description="List of input fields to be sent as request headers.")

@field_serializer('auth')
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Sep 21, 2025

Choose a reason for hiding this comment

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

Redundant serializer for 'auth' duplicates base CallTemplate logic; prefer relying on the base serializer to avoid duplication.

Prompt for AI agents
Address the following comment on plugins/communication_protocols/http/src/utcp_http/http_call_template.py at line 111:

<comment>Redundant serializer for &#39;auth&#39; duplicates base CallTemplate logic; prefer relying on the base serializer to avoid duplication.</comment>

<file context>
@@ -96,10 +103,49 @@ class HttpCallTemplate(CallTemplate):
     body_field: Optional[str] = Field(default=&quot;body&quot;, description=&quot;The name of the single input field to be sent as the request body.&quot;)
     header_fields: Optional[List[str]] = Field(default=None, description=&quot;List of input fields to be sent as request headers.&quot;)
 
+    @field_serializer(&#39;auth&#39;)
+    def serialize_auth(self, auth: Optional[Auth]) -&gt; Optional[dict]:
+        &quot;&quot;&quot;Serialize auth to dictionary.&quot;&quot;&quot;
</file context>

✅ Addressed in f378e67

h3xxit and others added 5 commits September 21, 2025 13:16
@h3xxit h3xxit merged commit 74a11e2 into main Sep 21, 2025
18 checks passed
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.

3 participants