Skip to content

Commit b482bf2

Browse files
Zie619claude
andcommitted
feat: add Python, TypeScript, and Go agent monitoring SDKs
- trusera-agent-sdk/ (Python): TruseraClient, @monitor decorator, LangChain/CrewAI/AutoGen integrations - trusera-sdk-js/ (TypeScript): HTTP interceptor, fetch monkey-patching, LangChain.js integration - trusera-sdk-go/ (Go): http.RoundTripper wrapper, zero deps, 85% test coverage - All SDKs support log/warn/block enforcement modes and event batching Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1d082a6 commit b482bf2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+10675
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
id-token: write
13+
contents: read
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.11'
23+
24+
- name: Install build dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install build hatchling
28+
29+
- name: Build package
30+
run: python -m build
31+
32+
- name: Publish to PyPI
33+
uses: pypa/gh-action-pypi-publish@release/v1
34+
with:
35+
password: ${{ secrets.PYPI_API_TOKEN }}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ['3.9', '3.10', '3.11', '3.12']
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install -e ".[dev,langchain,crewai,autogen]"
29+
30+
- name: Run tests
31+
run: pytest -v --tb=short
32+
33+
- name: Run linter
34+
run: ruff check .
35+
36+
- name: Run type checker
37+
run: mypy trusera_sdk

trusera-agent-sdk/.gitignore

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
build/
8+
develop-eggs/
9+
dist/
10+
downloads/
11+
eggs/
12+
.eggs/
13+
lib/
14+
lib64/
15+
parts/
16+
sdist/
17+
var/
18+
wheels/
19+
share/python-wheels/
20+
*.egg-info/
21+
.installed.cfg
22+
*.egg
23+
MANIFEST
24+
25+
# Virtual environments
26+
venv/
27+
env/
28+
ENV/
29+
env.bak/
30+
venv.bak/
31+
32+
# IDE
33+
.vscode/
34+
.idea/
35+
*.swp
36+
*.swo
37+
*~
38+
39+
# Testing
40+
.pytest_cache/
41+
.coverage
42+
htmlcov/
43+
.tox/
44+
.nox/
45+
46+
# Type checking
47+
.mypy_cache/
48+
.dmypy.json
49+
dmypy.json
50+
.pytype/
51+
52+
# Ruff
53+
.ruff_cache/
54+
55+
# OS
56+
.DS_Store
57+
Thumbs.db
58+
59+
# Project specific
60+
*.log
61+
.env
62+
.env.local

trusera-agent-sdk/.ruff.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Ruff configuration
2+
line-length = 100
3+
target-version = "py39"
4+
5+
[lint]
6+
select = [
7+
"E", # pycodestyle errors
8+
"F", # pyflakes
9+
"I", # isort
10+
"N", # pep8-naming
11+
"UP", # pyupgrade
12+
"B", # flake8-bugbear
13+
"A", # flake8-builtins
14+
"C4", # flake8-comprehensions
15+
"PT", # flake8-pytest-style
16+
]
17+
18+
ignore = [
19+
"E501", # line too long (handled by formatter)
20+
]
21+
22+
[lint.per-file-ignores]
23+
"__init__.py" = ["F401"] # Allow unused imports in __init__.py
24+
"tests/*" = ["S101"] # Allow assert in tests
25+
26+
[lint.isort]
27+
known-first-party = ["trusera_sdk"]
28+
29+
[format]
30+
quote-style = "double"
31+
indent-style = "space"

trusera-agent-sdk/CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Changelog
2+
3+
All notable changes to the Trusera Python SDK will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.1.0] - 2026-02-13
9+
10+
### Added
11+
- Initial release of the Trusera Python SDK
12+
- Core `TruseraClient` for event tracking and API communication
13+
- Event types: `TOOL_CALL`, `LLM_INVOKE`, `DATA_ACCESS`, `API_CALL`, `FILE_WRITE`, `DECISION`
14+
- `@monitor` decorator for automatic function tracking
15+
- Support for both sync and async functions
16+
- Automatic batching and background flushing
17+
- Context manager support for clean resource management
18+
- LangChain integration with `TruseraCallbackHandler`
19+
- CrewAI integration with `TruseraCrewCallback`
20+
- AutoGen integration with `TruseraAutoGenHook`
21+
- Comprehensive test suite with >90% coverage
22+
- Type hints throughout the codebase
23+
- Apache 2.0 license
24+
25+
### Framework Support
26+
- LangChain Core >=0.1.0
27+
- CrewAI >=0.1.0
28+
- AutoGen >=0.2.0
29+
30+
### Development Tools
31+
- pytest for testing
32+
- pytest-asyncio for async test support
33+
- ruff for linting
34+
- mypy for type checking
35+
- GitHub Actions for CI/CD
36+
37+
[0.1.0]: https://github.com/Trusera/trusera-agent-sdk/releases/tag/v0.1.0

trusera-agent-sdk/CONTRIBUTING.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# Contributing to Trusera SDK
2+
3+
Thank you for your interest in contributing to the Trusera Python SDK! This document provides guidelines and instructions for contributing.
4+
5+
## Getting Started
6+
7+
1. Fork the repository
8+
2. Clone your fork: `git clone https://github.com/YOUR_USERNAME/trusera-agent-sdk.git`
9+
3. Create a branch: `git checkout -b feature/your-feature-name`
10+
4. Make your changes
11+
5. Run tests: `pytest`
12+
6. Commit your changes: `git commit -m "Add your feature"`
13+
7. Push to your fork: `git push origin feature/your-feature-name`
14+
8. Open a Pull Request
15+
16+
## Development Setup
17+
18+
```bash
19+
# Create a virtual environment
20+
python -m venv venv
21+
source venv/bin/activate # On Windows: venv\Scripts\activate
22+
23+
# Install in development mode with all dependencies
24+
pip install -e ".[dev,langchain,crewai,autogen]"
25+
```
26+
27+
## Code Standards
28+
29+
### Style Guide
30+
31+
We follow PEP 8 and use several tools to enforce code quality:
32+
33+
```bash
34+
# Run linter
35+
ruff check .
36+
37+
# Auto-fix issues
38+
ruff check --fix .
39+
40+
# Type checking
41+
mypy trusera_sdk
42+
43+
# Format code (if using black)
44+
black trusera_sdk tests
45+
```
46+
47+
### Type Hints
48+
49+
All functions should have type hints:
50+
51+
```python
52+
def my_function(arg1: str, arg2: int) -> dict[str, Any]:
53+
"""Function with type hints."""
54+
return {"result": arg1 * arg2}
55+
```
56+
57+
### Docstrings
58+
59+
Use Google-style docstrings:
60+
61+
```python
62+
def my_function(arg1: str, arg2: int) -> str:
63+
"""
64+
Brief description of the function.
65+
66+
Longer description if needed.
67+
68+
Args:
69+
arg1: Description of arg1
70+
arg2: Description of arg2
71+
72+
Returns:
73+
Description of return value
74+
75+
Raises:
76+
ValueError: When something goes wrong
77+
"""
78+
pass
79+
```
80+
81+
## Testing
82+
83+
### Running Tests
84+
85+
```bash
86+
# Run all tests
87+
pytest
88+
89+
# Run specific test file
90+
pytest tests/test_client.py
91+
92+
# Run with coverage
93+
pytest --cov=trusera_sdk --cov-report=html
94+
```
95+
96+
### Writing Tests
97+
98+
- Place tests in the `tests/` directory
99+
- Name test files `test_*.py`
100+
- Name test functions `test_*`
101+
- Use descriptive test names
102+
- Aim for high test coverage (>90%)
103+
104+
Example test:
105+
106+
```python
107+
def test_my_feature(trusera_client):
108+
"""Test my new feature."""
109+
result = trusera_client.my_feature()
110+
assert result is not None
111+
assert result["status"] == "success"
112+
```
113+
114+
## Pull Request Process
115+
116+
1. **Update Tests**: Add or update tests for your changes
117+
2. **Update Documentation**: Update README.md or docstrings as needed
118+
3. **Run All Tests**: Ensure all tests pass
119+
4. **Check Code Quality**: Run linter and type checker
120+
5. **Write Clear Commit Messages**: Use descriptive commit messages
121+
6. **Update Changelog**: Add a note about your changes
122+
7. **Submit PR**: Open a pull request with a clear description
123+
124+
### PR Description Template
125+
126+
```markdown
127+
## Description
128+
Brief description of changes
129+
130+
## Type of Change
131+
- [ ] Bug fix
132+
- [ ] New feature
133+
- [ ] Breaking change
134+
- [ ] Documentation update
135+
136+
## Testing
137+
How has this been tested?
138+
139+
## Checklist
140+
- [ ] Tests pass
141+
- [ ] Code follows style guidelines
142+
- [ ] Documentation updated
143+
- [ ] Changelog updated
144+
```
145+
146+
## Adding Framework Integrations
147+
148+
To add support for a new AI framework:
149+
150+
1. Create `trusera_sdk/integrations/your_framework.py`
151+
2. Implement the integration following existing patterns
152+
3. Add tests in `tests/test_your_framework.py`
153+
4. Add to `pyproject.toml` optional dependencies
154+
5. Update README.md with usage example
155+
156+
## Reporting Bugs
157+
158+
Open an issue with:
159+
- Clear title
160+
- Steps to reproduce
161+
- Expected behavior
162+
- Actual behavior
163+
- Environment details (Python version, OS, SDK version)
164+
- Code sample if possible
165+
166+
## Feature Requests
167+
168+
Open an issue with:
169+
- Clear description of the feature
170+
- Use case / motivation
171+
- Example API if proposing new functionality
172+
173+
## Questions
174+
175+
For questions about using the SDK:
176+
- Check the [documentation](https://docs.trusera.dev)
177+
- Search existing issues
178+
- Open a new issue with the "question" label
179+
180+
## License
181+
182+
By contributing, you agree that your contributions will be licensed under the Apache License 2.0.
183+
184+
## Code of Conduct
185+
186+
Be respectful and constructive in all interactions.
187+
188+
Thank you for contributing to Trusera!

0 commit comments

Comments
 (0)