Skip to content

Commit 20a24e5

Browse files
committed
feat: Introduce Module protocol and expose new schema and utility functions.
1 parent 55205fc commit 20a24e5

File tree

5 files changed

+68
-6
lines changed

5 files changed

+68
-6
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ Schema-driven module development framework for AI-perceivable interfaces.
2424
- **Async task management** -- Background module execution with status tracking, cancellation, and concurrency limiting
2525
- **W3C Trace Context** -- traceparent header injection/extraction for distributed tracing interop
2626

27+
## Documentation
28+
29+
For full documentation, including Quick Start guides for both Python and TypeScript, visit:
30+
**[https://aipartnerup.github.io/apcore/getting-started.html](https://aipartnerup.github.io/apcore/getting-started.html)**
31+
2732
## Requirements
2833

2934
- Python >= 3.11

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "apcore"
7-
version = "0.7.0"
7+
version = "0.7.1"
88
description = "Schema-driven module development framework for AI-perceivable interfaces"
99
readme = "README.md"
1010
requires-python = ">=3.11"

src/apcore/__init__.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from apcore.executor import Executor, redact_sensitive, REDACTED_VALUE
2727

2828
# Module types
29-
from apcore.module import ModuleAnnotations, ModuleExample, ValidationResult
29+
from apcore.module import Module, ModuleAnnotations, ModuleExample, ValidationResult
3030

3131
# Config
3232
from apcore.config import Config
@@ -92,6 +92,18 @@
9292
# Bindings
9393
from apcore.bindings import BindingLoader
9494

95+
# Schema
96+
from apcore.schema import (
97+
SchemaLoader as SchemaLoader,
98+
SchemaValidator as SchemaValidator,
99+
SchemaExporter as SchemaExporter,
100+
RefResolver as RefResolver,
101+
to_strict_schema as to_strict_schema,
102+
)
103+
104+
# Utilities (pattern matching)
105+
from apcore.utils import match_pattern as match_pattern
106+
95107
# Observability
96108
from apcore.observability import (
97109
ContextLogger,
@@ -109,7 +121,7 @@
109121
# Trace Context
110122
from apcore.trace_context import TraceContext, TraceParent
111123

112-
__version__ = "0.7.0"
124+
__version__ = "0.7.1"
113125

114126
__all__ = [
115127
# Core
@@ -128,6 +140,7 @@
128140
"AutoApproveHandler",
129141
"CallbackApprovalHandler",
130142
# Module types
143+
"Module",
131144
"ModuleAnnotations",
132145
"ModuleExample",
133146
"ValidationResult",
@@ -200,7 +213,14 @@
200213
"TaskInfo",
201214
# Bindings
202215
"BindingLoader",
216+
# Schema
217+
"SchemaLoader",
218+
"SchemaValidator",
219+
"SchemaExporter",
220+
"RefResolver",
221+
"to_strict_schema",
203222
# Utilities
223+
"match_pattern",
204224
"redact_sensitive",
205225
"REDACTED_VALUE",
206226
# Observability

src/apcore/module.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
1-
"""Module abstract base class and related data types."""
1+
"""Module protocol and related data types."""
22

33
from __future__ import annotations
44

55
from dataclasses import dataclass, field
66

7-
from typing import Any
7+
from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable
88

9-
__all__ = ["ModuleAnnotations", "ModuleExample", "ValidationResult"]
9+
if TYPE_CHECKING:
10+
from pydantic import BaseModel
11+
12+
from apcore.context import Context
13+
14+
__all__ = ["Module", "ModuleAnnotations", "ModuleExample", "ValidationResult"]
15+
16+
17+
@runtime_checkable
18+
class Module(Protocol):
19+
"""Protocol for apcore modules.
20+
21+
Any class with ``input_schema``, ``output_schema``, ``description``,
22+
and an ``execute(inputs, context)`` method satisfies this protocol.
23+
Inheriting from ``Module`` is optional but provides IDE autocompletion.
24+
25+
At runtime, ``@runtime_checkable`` only checks attribute existence.
26+
Static type checkers (pyright) will verify the full signature.
27+
"""
28+
29+
input_schema: type[BaseModel]
30+
output_schema: type[BaseModel]
31+
description: str
32+
33+
def execute(self, inputs: dict[str, Any], context: Context) -> dict[str, Any]: ...
1034

1135

1236
@dataclass(frozen=True)

tests/test_public_api.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ def test_executor_importable(self):
3737

3838
# -- Module types --
3939

40+
def test_module_importable(self):
41+
from apcore import Module
42+
43+
assert Module is not None
44+
4045
def test_module_annotations_importable(self):
4146
from apcore import ModuleAnnotations
4247

@@ -327,6 +332,7 @@ class TestPublicAPIAll:
327332
"AutoApproveHandler",
328333
"CallbackApprovalHandler",
329334
# Module types
335+
"Module",
330336
"ModuleAnnotations",
331337
"ModuleExample",
332338
"ValidationResult",
@@ -399,7 +405,14 @@ class TestPublicAPIAll:
399405
"TaskInfo",
400406
# Bindings
401407
"BindingLoader",
408+
# Schema
409+
"SchemaLoader",
410+
"SchemaValidator",
411+
"SchemaExporter",
412+
"RefResolver",
413+
"to_strict_schema",
402414
# Utilities
415+
"match_pattern",
403416
"redact_sensitive",
404417
"REDACTED_VALUE",
405418
# Observability

0 commit comments

Comments
 (0)