api-operator 0.9.0__tar.gz → 0.11.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. api_operator-0.11.0/.env.example +13 -0
  2. api_operator-0.11.0/CHANGELOG.md +61 -0
  3. api_operator-0.11.0/Dockerfile +12 -0
  4. {api_operator-0.9.0 → api_operator-0.11.0}/PKG-INFO +66 -52
  5. api_operator-0.11.0/README.md +183 -0
  6. api_operator-0.11.0/api_operator/__init__.py +37 -0
  7. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/adapters/base.py +4 -0
  8. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/adapters/mock.py +36 -0
  9. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/adapters/openapi_generator.py +81 -4
  10. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/adapters/yaml_adapter.py +71 -1
  11. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/adapters/yaml_spec.py +3 -0
  12. api_operator-0.11.0/api_operator/core/agent.py +482 -0
  13. api_operator-0.11.0/api_operator/core/audit.py +87 -0
  14. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/core/config.py +6 -0
  15. api_operator-0.11.0/api_operator/core/formatters.py +169 -0
  16. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/core/planner.py +65 -6
  17. api_operator-0.11.0/api_operator/core/policy.py +232 -0
  18. api_operator-0.11.0/api_operator/core/quota.py +78 -0
  19. api_operator-0.11.0/api_operator/core/redaction.py +46 -0
  20. api_operator-0.11.0/api_operator/core/schemas.py +142 -0
  21. api_operator-0.11.0/api_operator/factory.py +59 -0
  22. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/server/app.py +29 -2
  23. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/server/cli.py +37 -5
  24. api_operator-0.11.0/docs/ROADMAP-vNEXT.md +481 -0
  25. api_operator-0.11.0/docs/audit.md +26 -0
  26. api_operator-0.11.0/docs/dry-run.md +30 -0
  27. api_operator-0.11.0/docs/policy.md +42 -0
  28. api_operator-0.11.0/docs/public-api-inventory.md +56 -0
  29. api_operator-0.11.0/docs/quotas.md +25 -0
  30. api_operator-0.11.0/examples/jsonplaceholder-adapter/README.md +16 -0
  31. api_operator-0.11.0/examples/jsonplaceholder-adapter/adapter.yaml +57 -0
  32. api_operator-0.11.0/examples/jsonplaceholder-adapter/policy.yaml +21 -0
  33. {api_operator-0.9.0 → api_operator-0.11.0}/examples/tenant-kit-adapter/adapter.yaml +10 -0
  34. api_operator-0.11.0/examples/tenant-kit-adapter/policy.yaml +24 -0
  35. {api_operator-0.9.0 → api_operator-0.11.0}/pyproject.toml +2 -2
  36. {api_operator-0.9.0 → api_operator-0.11.0}/tests/test_agent.py +1 -1
  37. {api_operator-0.9.0 → api_operator-0.11.0}/tests/test_api.py +1 -1
  38. api_operator-0.11.0/tests/test_audit.py +89 -0
  39. {api_operator-0.9.0 → api_operator-0.11.0}/tests/test_cli.py +1 -1
  40. {api_operator-0.9.0 → api_operator-0.11.0}/tests/test_core.py +24 -0
  41. api_operator-0.11.0/tests/test_dry_run.py +112 -0
  42. api_operator-0.11.0/tests/test_formatters.py +36 -0
  43. {api_operator-0.9.0 → api_operator-0.11.0}/tests/test_mock_adapter.py +1 -1
  44. api_operator-0.11.0/tests/test_openapi_policy.py +149 -0
  45. api_operator-0.11.0/tests/test_policy.py +209 -0
  46. api_operator-0.11.0/tests/test_quota.py +55 -0
  47. {api_operator-0.9.0 → api_operator-0.11.0}/tests/test_scenarios_e2e.py +2 -1
  48. {api_operator-0.9.0 → api_operator-0.11.0}/tests/test_yaml_adapter.py +36 -1
  49. api_operator-0.9.0/.env.example +0 -6
  50. api_operator-0.9.0/CHANGELOG.md +0 -24
  51. api_operator-0.9.0/README.md +0 -169
  52. api_operator-0.9.0/api_operator/__init__.py +0 -8
  53. api_operator-0.9.0/api_operator/core/agent.py +0 -160
  54. api_operator-0.9.0/api_operator/factory.py +0 -26
  55. {api_operator-0.9.0 → api_operator-0.11.0}/.github/workflows/tests.yml +0 -0
  56. {api_operator-0.9.0 → api_operator-0.11.0}/.gitignore +0 -0
  57. {api_operator-0.9.0 → api_operator-0.11.0}/LICENSE +0 -0
  58. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/adapters/__init__.py +0 -0
  59. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/adapters/registry.py +0 -0
  60. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/core/executor.py +0 -0
  61. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/core/guardrails.py +0 -0
  62. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/core/memory.py +0 -0
  63. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/core/planner_openai.py +0 -0
  64. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/rag/indexer.py +0 -0
  65. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/tools/base.py +0 -0
  66. {api_operator-0.9.0 → api_operator-0.11.0}/api_operator/tools/schema.py +0 -0
  67. {api_operator-0.9.0 → api_operator-0.11.0}/examples/tenant-kit-adapter/README.md +0 -0
  68. {api_operator-0.9.0 → api_operator-0.11.0}/scripts/integration_tenant_kit.py +0 -0
  69. {api_operator-0.9.0 → api_operator-0.11.0}/tests/__init__.py +0 -0
  70. {api_operator-0.9.0 → api_operator-0.11.0}/tests/test_integration_tenant_kit.py +0 -0
@@ -0,0 +1,13 @@
1
+ api_operator_HOST=127.0.0.1
2
+ api_operator_PORT=8100
3
+ api_operator_DEFAULT_ADAPTER=mock
4
+ api_operator_PLANNER=mock
5
+ # api_operator_OPENAI_API_KEY=
6
+ # api_operator_OPENAI_MODEL=gpt-4o-mini
7
+ api_operator_REQUIRE_CONFIRM_DANGEROUS=true
8
+ api_operator_AUDIT_ENABLED=true
9
+ # api_operator_AUDIT_PATH=./audit.jsonl
10
+ # api_operator_POLICY_PATH=./policy.yaml
11
+ # api_operator_QUOTA_BUDGET=100
12
+ api_operator_DRY_RUN=false
13
+ # api_operator_CORS_ORIGINS=http://localhost:3000
@@ -0,0 +1,61 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ ## [0.11.0] - 2026-11-23
6
+
7
+ Foundation for **Safe API Agent** (see `docs/ROADMAP-vNEXT.md`). Opt-in; existing adapters keep working.
8
+
9
+ ### Added
10
+
11
+ - **Policy engine** (`policy.yaml`): allow / deny / confirm, deny lists, confirm lists, session `max_calls`, role/tenant rules
12
+ - **Dry-run**: CLI `--dry-run`, HTTP `dry_run=true`, `DryRunReport` + YAML `would_call` preview
13
+ - **Audit**: `AuditSink` protocol, JSONL / memory sinks, sensitive-field redaction
14
+ - **Quota hooks**: `QuotaGateway` + in-memory budget gateway (host owns real billing)
15
+ - Shared schemas: `PolicyDecision`, `QuotaReservation`, `AuditEvent`, `DryRunReport`
16
+ - Docs: `docs/policy.md`, `docs/dry-run.md`, `docs/audit.md`, `docs/quotas.md`, `docs/public-api-inventory.md`
17
+ - Example `examples/tenant-kit-adapter/policy.yaml`
18
+ - Example `examples/jsonplaceholder-adapter/` (public REST, non–tenant-kit)
19
+ - OpenAPI generator: tag-based `requires_ability`, write methods marked dangerous, draft `policy.yaml`
20
+ - `scaffold-adapter` also writes `policy.yaml`
21
+
22
+ ### Changed
23
+
24
+ - Agent `status` may be `deny` (additive) for policy/quota/ability rejection
25
+ - README reframed as **Safe API Agent**; version `0.11.0`
26
+
27
+ ## [0.10.0] - 2026-06-15
28
+
29
+ ### Added
30
+
31
+ - YAML adapter `connect_host` — route HTTP to an internal host (e.g. Docker `nginx`) while preserving logical `Host` headers for multi-tenant subdomains
32
+ - Optional CORS for `api-operator serve` via `API_OPERATOR_CORS_ORIGINS` (comma-separated)
33
+ - `Dockerfile` for containerized deployments
34
+ - `formatters.py` — human-readable tool success messages (no raw JSON in chat replies)
35
+ - Mock adapter tools: `get_usage`, `get_subscription`
36
+
37
+ ### Changed
38
+
39
+ - Mock planner — friendlier help text and NL patterns for tenant-kit flows
40
+ - FastAPI app version metadata updated to 0.10.0
41
+
42
+ ## [0.9.0] - 2026-06-14
43
+
44
+ Renamed to **`api-operator`** (GitHub + PyPI). PyPI blocks names starting with `operator` (stdlib conflict).
45
+
46
+ ### Added
47
+
48
+ - Core agent runtime: planning, guardrails, tool execution, session memory
49
+ - `mock` adapter for offline demos and tests
50
+ - `yaml` adapter — configure HTTP tools without Python
51
+ - OpenAPI scaffold CLI (`generate-from-openapi`, `scaffold-adapter`)
52
+ - CLI: `chat`, `demo`, `tools`, `serve`
53
+ - FastAPI server: `/health`, `/v1/adapters`, `/v1/tools`, `/v1/chat`
54
+ - Example adapter for [Laravel Tenant Kit](https://github.com/mohammedelkarsh/laravel-tenant-kit)
55
+ - Live integration script: `scripts/integration_tenant_kit.py`
56
+ - 69 unit tests; optional pytest integration marker
57
+
58
+ ### Notes
59
+
60
+ - Default planner is rule-based (`mock`); OpenAI planner is optional (`pip install api-operator[llm]`)
61
+ - Tenant team invites require a tenant-scoped Sanctum token (see example adapter README)
@@ -0,0 +1,12 @@
1
+ FROM python:3.12-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY pyproject.toml README.md LICENSE ./
6
+ COPY api_operator ./api_operator
7
+
8
+ RUN pip install --no-cache-dir .
9
+
10
+ EXPOSE 8100
11
+
12
+ CMD ["api-operator", "serve", "--host", "0.0.0.0", "--port", "8100", "--adapter", "yaml", "--planner", "mock"]
@@ -1,7 +1,7 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: api-operator
3
- Version: 0.9.0
4
- Summary: Standalone AI API Operator with pluggable adapters for multi-project APIs
3
+ Version: 0.11.0
4
+ Summary: Safe API Agent — run APIs with policy, quotas, and audit (pluggable adapters)
5
5
  Project-URL: Homepage, https://github.com/mohammedelkarsh/api-operator
6
6
  Project-URL: Repository, https://github.com/mohammedelkarsh/api-operator
7
7
  Project-URL: Issues, https://github.com/mohammedelkarsh/api-operator/issues
@@ -35,28 +35,33 @@ Provides-Extra: llm
35
35
  Requires-Dist: openai>=1.35.0; extra == 'llm'
36
36
  Description-Content-Type: text/markdown
37
37
 
38
- # API Operator
38
+ # API Operator — Safe API Agent
39
39
 
40
40
  [![Tests](https://github.com/mohammedelkarsh/api-operator/actions/workflows/tests.yml/badge.svg)](https://github.com/mohammedelkarsh/api-operator/actions/workflows/tests.yml)
41
+ [![PyPI](https://img.shields.io/pypi/v/api-operator.svg)](https://pypi.org/project/api-operator/)
41
42
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
42
43
  [![Python](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
43
44
 
44
- Standalone **AI operator runtime** with pluggable adapters. Talk to your HTTP APIs instead of clicking through admin panels.
45
+ Turn any OpenAPI / `adapter.yaml` into an AI agent that can **reason and act on your APIs** with **policy, dry-run, audit, and quota hooks**.
45
46
 
46
- Works with Laravel, Go, connectivity platforms, or any backend with a REST API.
47
+ > Retrieve (optional later) → Reason → Act — with permission, cost, and audit boundaries.
48
+
49
+ Works with Laravel, Go, or any REST API. First-class example: [laravel-tenant-kit](https://github.com/mohammedelkarsh/laravel-tenant-kit).
47
50
 
48
51
  ## Install
49
52
 
50
53
  ```bash
51
- git clone https://github.com/mohammedelkarsh/api-operator.git
52
- cd api-operator
53
- pip install -e ".[dev]"
54
+ pip install api-operator
55
+ # optional OpenAI planner
56
+ pip install "api-operator[llm]"
54
57
  ```
55
58
 
56
- Optional OpenAI planner:
59
+ Development:
57
60
 
58
61
  ```bash
59
- pip install -e ".[dev,llm]"
62
+ git clone https://github.com/mohammedelkarsh/api-operator.git
63
+ cd api-operator
64
+ pip install -e ".[dev]"
60
65
  ```
61
66
 
62
67
  ## Quick start
@@ -64,27 +69,52 @@ pip install -e ".[dev,llm]"
64
69
  ```bash
65
70
  api-operator demo
66
71
  api-operator tools --adapter mock
72
+ api-operator chat --adapter mock --dry-run
67
73
  ```
68
74
 
69
- ## What ships in the core package
75
+ Public API demo (no Laravel):
76
+
77
+ ```bash
78
+ api-operator chat \
79
+ --adapter yaml \
80
+ --config examples/jsonplaceholder-adapter/adapter.yaml \
81
+ --dry-run
82
+ ```
83
+
84
+ ## What ships in the core
70
85
 
71
86
  | In core | In your projects |
72
87
  |---------|------------------|
73
- | Agent runtime (plan, guard, execute) | `adapter.yaml` per API |
74
- | `mock` adapter (demo + tests) | OpenAPI specs |
75
- | `yaml` adapter | API tokens in `.env` |
76
- | CLI + HTTP server | Optional custom adapters |
88
+ | Agent runtime (plan → policy → quota → execute) | `adapter.yaml` + optional `policy.yaml` |
89
+ | Dry-run (`--dry-run` / `dry_run=true`) | OpenAPI specs |
90
+ | AuditSink + redaction | API tokens in `.env` |
91
+ | QuotaGateway hooks | Host billing (e.g. tenant-kit meters) |
92
+ | `mock` + `yaml` adapters | Optional custom adapters |
93
+
94
+ No hard dependency on Laravel, Postgres, or vector DBs.
95
+
96
+ ## Safe by default
97
+
98
+ 1. **Policy** — optional `policy.yaml` (allow / deny / confirm, session caps, roles)
99
+ 2. **Dry-run** — see the planned tool + upstream request without side effects
100
+ 3. **Audit** — JSONL / injectable sink; secrets redacted
101
+ 4. **Quota** — gate before execute; real billing stays in the host app
102
+
103
+ Docs: [policy](docs/policy.md) · [dry-run](docs/dry-run.md) · [audit](docs/audit.md) · [quotas](docs/quotas.md) · [roadmap](docs/ROADMAP-vNEXT.md)
77
104
 
78
105
  ## Build an adapter without Python
79
106
 
80
- ### Scaffold template
107
+ ### Scaffold
81
108
 
82
109
  ```bash
83
110
  api-operator scaffold-adapter my-api --output examples
111
+ # writes adapter.yaml + policy.yaml + README
84
112
  ```
85
113
 
86
114
  ### Generate from OpenAPI
87
115
 
116
+ Write methods (`POST`/`PATCH`/`PUT`/`DELETE`) are marked `dangerous`. Tag-based abilities are suggested. A draft `policy.yaml` is written next to the adapter.
117
+
88
118
  ```bash
89
119
  api-operator generate-from-openapi openapi.yaml \
90
120
  --output adapter.yaml \
@@ -92,9 +122,12 @@ api-operator generate-from-openapi openapi.yaml \
92
122
  --path-prefix /api
93
123
  ```
94
124
 
95
- ### Laravel Tenant Kit example
125
+ ### Examples
96
126
 
97
- See [`examples/tenant-kit-adapter/`](examples/tenant-kit-adapter/) — pairs with [laravel-tenant-kit](https://github.com/mohammedelkarsh/laravel-tenant-kit).
127
+ | Example | Purpose |
128
+ |---------|---------|
129
+ | [`examples/tenant-kit-adapter/`](examples/tenant-kit-adapter/) | Laravel Tenant Kit |
130
+ | [`examples/jsonplaceholder-adapter/`](examples/jsonplaceholder-adapter/) | Public REST demo |
98
131
 
99
132
  ```bash
100
133
  export TENANT_KIT_API_TOKEN="your-sanctum-token"
@@ -120,12 +153,14 @@ tools:
120
153
  description: List items
121
154
  method: GET
122
155
  path: /api/items
156
+ requires_ability: items:read
123
157
 
124
158
  - name: create_item
125
159
  description: Create item
126
160
  method: POST
127
161
  path: /api/items
128
162
  dangerous: true
163
+ requires_ability: items:write
129
164
  parameters:
130
165
  title:
131
166
  type: string
@@ -134,18 +169,7 @@ tools:
134
169
  title: "{title}"
135
170
  ```
136
171
 
137
- Tenant subdomain APIs:
138
-
139
- ```yaml
140
- - name: invite_member
141
- method: POST
142
- path: /api/team/invitations
143
- host: tenant
144
- tenant_param: subdomain
145
- parameters:
146
- subdomain: { type: string, required: true }
147
- email: { type: string, required: true }
148
- ```
172
+ Optional sibling `policy.yaml` loads automatically when you pass that adapter path.
149
173
 
150
174
  ## HTTP server
151
175
 
@@ -160,45 +184,35 @@ POST /v1/chat
160
184
  "config_path": "examples/tenant-kit-adapter/adapter.yaml",
161
185
  "adapter_config": { "token": "YOUR_TOKEN" },
162
186
  "message": "list workspaces",
163
- "abilities": ["workspaces:read"]
187
+ "abilities": ["workspaces:read"],
188
+ "dry_run": false
164
189
  }
165
190
  ```
166
191
 
167
- ## Integration test (Tenant Kit)
168
-
169
- With [Tenant Kit](https://github.com/mohammedelkarsh/laravel-tenant-kit) running:
192
+ ## Tests
170
193
 
171
194
  ```bash
172
- python scripts/integration_tenant_kit.py
173
- # Docker on port 8080:
174
- python scripts/integration_tenant_kit.py --base-url http://laravel-tenant-kit.test:8080
195
+ pytest -q
175
196
  ```
176
197
 
177
- Optional pytest marker (requires env vars):
198
+ Live Tenant Kit (optional):
178
199
 
179
200
  ```bash
180
- export TENANT_KIT_BASE_URL=http://laravel-tenant-kit.test
181
- export TENANT_KIT_API_TOKEN=your-token
201
+ python scripts/integration_tenant_kit.py
182
202
  pytest -m integration -q
183
203
  ```
184
204
 
185
- ## Tests
186
-
187
- ```bash
188
- pytest -q
189
- ```
190
-
191
205
  ## Configuration
192
206
 
193
- Copy `.env.example` to `.env` for local defaults (`api_operator_PLANNER`, port, etc.).
207
+ Copy `.env.example` → `.env`. Notable vars: `API_OPERATOR_PLANNER`, `API_OPERATOR_POLICY_PATH`, `API_OPERATOR_AUDIT_PATH`, `API_OPERATOR_QUOTA_BUDGET`, `API_OPERATOR_DRY_RUN`.
194
208
 
195
209
  ## Architecture
196
210
 
197
211
  ```
198
- api-operator (core) your projects
199
- ├── agent runtime ├── adapter.yaml
200
- ├── mock + yaml adapters ├── openapi.yaml
201
- └── scaffold / generate CLI └── HTTP APIs (Laravel, Go, …)
212
+ api-operator (Safe API Agent) your hosts
213
+ ├── plan → policy → quota → act ├── adapter.yaml + policy.yaml
214
+ ├── dry-run + audit hooks ├── OpenAPI
215
+ └── mock / yaml adapters └── Laravel / any REST API
202
216
  ```
203
217
 
204
218
  ## License
@@ -0,0 +1,183 @@
1
+ # API Operator — Safe API Agent
2
+
3
+ [![Tests](https://github.com/mohammedelkarsh/api-operator/actions/workflows/tests.yml/badge.svg)](https://github.com/mohammedelkarsh/api-operator/actions/workflows/tests.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/api-operator.svg)](https://pypi.org/project/api-operator/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+ [![Python](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
7
+
8
+ Turn any OpenAPI / `adapter.yaml` into an AI agent that can **reason and act on your APIs** with **policy, dry-run, audit, and quota hooks**.
9
+
10
+ > Retrieve (optional later) → Reason → Act — with permission, cost, and audit boundaries.
11
+
12
+ Works with Laravel, Go, or any REST API. First-class example: [laravel-tenant-kit](https://github.com/mohammedelkarsh/laravel-tenant-kit).
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ pip install api-operator
18
+ # optional OpenAI planner
19
+ pip install "api-operator[llm]"
20
+ ```
21
+
22
+ Development:
23
+
24
+ ```bash
25
+ git clone https://github.com/mohammedelkarsh/api-operator.git
26
+ cd api-operator
27
+ pip install -e ".[dev]"
28
+ ```
29
+
30
+ ## Quick start
31
+
32
+ ```bash
33
+ api-operator demo
34
+ api-operator tools --adapter mock
35
+ api-operator chat --adapter mock --dry-run
36
+ ```
37
+
38
+ Public API demo (no Laravel):
39
+
40
+ ```bash
41
+ api-operator chat \
42
+ --adapter yaml \
43
+ --config examples/jsonplaceholder-adapter/adapter.yaml \
44
+ --dry-run
45
+ ```
46
+
47
+ ## What ships in the core
48
+
49
+ | In core | In your projects |
50
+ |---------|------------------|
51
+ | Agent runtime (plan → policy → quota → execute) | `adapter.yaml` + optional `policy.yaml` |
52
+ | Dry-run (`--dry-run` / `dry_run=true`) | OpenAPI specs |
53
+ | AuditSink + redaction | API tokens in `.env` |
54
+ | QuotaGateway hooks | Host billing (e.g. tenant-kit meters) |
55
+ | `mock` + `yaml` adapters | Optional custom adapters |
56
+
57
+ No hard dependency on Laravel, Postgres, or vector DBs.
58
+
59
+ ## Safe by default
60
+
61
+ 1. **Policy** — optional `policy.yaml` (allow / deny / confirm, session caps, roles)
62
+ 2. **Dry-run** — see the planned tool + upstream request without side effects
63
+ 3. **Audit** — JSONL / injectable sink; secrets redacted
64
+ 4. **Quota** — gate before execute; real billing stays in the host app
65
+
66
+ Docs: [policy](docs/policy.md) · [dry-run](docs/dry-run.md) · [audit](docs/audit.md) · [quotas](docs/quotas.md) · [roadmap](docs/ROADMAP-vNEXT.md)
67
+
68
+ ## Build an adapter without Python
69
+
70
+ ### Scaffold
71
+
72
+ ```bash
73
+ api-operator scaffold-adapter my-api --output examples
74
+ # writes adapter.yaml + policy.yaml + README
75
+ ```
76
+
77
+ ### Generate from OpenAPI
78
+
79
+ Write methods (`POST`/`PATCH`/`PUT`/`DELETE`) are marked `dangerous`. Tag-based abilities are suggested. A draft `policy.yaml` is written next to the adapter.
80
+
81
+ ```bash
82
+ api-operator generate-from-openapi openapi.yaml \
83
+ --output adapter.yaml \
84
+ --base-url http://api.example.test \
85
+ --path-prefix /api
86
+ ```
87
+
88
+ ### Examples
89
+
90
+ | Example | Purpose |
91
+ |---------|---------|
92
+ | [`examples/tenant-kit-adapter/`](examples/tenant-kit-adapter/) | Laravel Tenant Kit |
93
+ | [`examples/jsonplaceholder-adapter/`](examples/jsonplaceholder-adapter/) | Public REST demo |
94
+
95
+ ```bash
96
+ export TENANT_KIT_API_TOKEN="your-sanctum-token"
97
+ api-operator chat \
98
+ --adapter yaml \
99
+ --config examples/tenant-kit-adapter/adapter.yaml \
100
+ --base-url http://laravel-tenant-kit.test
101
+ ```
102
+
103
+ ## adapter.yaml (minimal)
104
+
105
+ ```yaml
106
+ name: my_project
107
+ description: My API adapter
108
+ base_url: http://api.example.test
109
+
110
+ auth:
111
+ type: bearer
112
+ env_token: MY_PROJECT_API_TOKEN
113
+
114
+ tools:
115
+ - name: list_items
116
+ description: List items
117
+ method: GET
118
+ path: /api/items
119
+ requires_ability: items:read
120
+
121
+ - name: create_item
122
+ description: Create item
123
+ method: POST
124
+ path: /api/items
125
+ dangerous: true
126
+ requires_ability: items:write
127
+ parameters:
128
+ title:
129
+ type: string
130
+ required: true
131
+ body:
132
+ title: "{title}"
133
+ ```
134
+
135
+ Optional sibling `policy.yaml` loads automatically when you pass that adapter path.
136
+
137
+ ## HTTP server
138
+
139
+ ```bash
140
+ api-operator serve --port 8100
141
+ ```
142
+
143
+ ```json
144
+ POST /v1/chat
145
+ {
146
+ "adapter": "yaml",
147
+ "config_path": "examples/tenant-kit-adapter/adapter.yaml",
148
+ "adapter_config": { "token": "YOUR_TOKEN" },
149
+ "message": "list workspaces",
150
+ "abilities": ["workspaces:read"],
151
+ "dry_run": false
152
+ }
153
+ ```
154
+
155
+ ## Tests
156
+
157
+ ```bash
158
+ pytest -q
159
+ ```
160
+
161
+ Live Tenant Kit (optional):
162
+
163
+ ```bash
164
+ python scripts/integration_tenant_kit.py
165
+ pytest -m integration -q
166
+ ```
167
+
168
+ ## Configuration
169
+
170
+ Copy `.env.example` → `.env`. Notable vars: `API_OPERATOR_PLANNER`, `API_OPERATOR_POLICY_PATH`, `API_OPERATOR_AUDIT_PATH`, `API_OPERATOR_QUOTA_BUDGET`, `API_OPERATOR_DRY_RUN`.
171
+
172
+ ## Architecture
173
+
174
+ ```
175
+ api-operator (Safe API Agent) your hosts
176
+ ├── plan → policy → quota → act ├── adapter.yaml + policy.yaml
177
+ ├── dry-run + audit hooks ├── OpenAPI
178
+ └── mock / yaml adapters └── Laravel / any REST API
179
+ ```
180
+
181
+ ## License
182
+
183
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,37 @@
1
+ """API Operator — Safe API Agent with pluggable adapters."""
2
+
3
+ from api_operator.core.agent import Agent, AgentResponse
4
+ from api_operator.core.config import Settings
5
+ from api_operator.core.audit import AuditSink, JsonlAuditSink, MemoryAuditSink
6
+ from api_operator.core.policy import PolicyContext, PolicyEngine
7
+ from api_operator.core.quota import InMemoryQuotaGateway, QuotaGateway, UnlimitedQuotaGateway
8
+ from api_operator.core.schemas import (
9
+ AuditEvent,
10
+ Decision,
11
+ DryRunReport,
12
+ PolicyDecision,
13
+ QuotaReservation,
14
+ )
15
+ from api_operator.tools.base import Tool, ToolRegistry
16
+
17
+ __all__ = [
18
+ "Agent",
19
+ "AgentResponse",
20
+ "AuditEvent",
21
+ "AuditSink",
22
+ "Decision",
23
+ "DryRunReport",
24
+ "InMemoryQuotaGateway",
25
+ "JsonlAuditSink",
26
+ "MemoryAuditSink",
27
+ "PolicyContext",
28
+ "PolicyDecision",
29
+ "PolicyEngine",
30
+ "QuotaGateway",
31
+ "QuotaReservation",
32
+ "Settings",
33
+ "Tool",
34
+ "ToolRegistry",
35
+ "UnlimitedQuotaGateway",
36
+ ]
37
+ __version__ = "0.11.0"
@@ -23,3 +23,7 @@ class Adapter(ABC):
23
23
 
24
24
  def docs_paths(self) -> list[str]:
25
25
  return []
26
+
27
+ def preview_tool_call(self, tool_name: str, arguments: dict[str, Any]) -> dict[str, Any] | None:
28
+ """Optional dry-run preview of the upstream request. Default: unsupported."""
29
+ return None
@@ -62,6 +62,24 @@ class MockAdapter(Adapter):
62
62
  parameters={},
63
63
  )
64
64
  )
65
+ registry.register(
66
+ Tool(
67
+ name="get_usage",
68
+ description="Get usage metrics for a workspace",
69
+ handler=self._get_usage,
70
+ parameters={"workspace_id": str},
71
+ required=["workspace_id"],
72
+ )
73
+ )
74
+ registry.register(
75
+ Tool(
76
+ name="get_subscription",
77
+ description="Get subscription details for a workspace",
78
+ handler=self._get_subscription,
79
+ parameters={"workspace_id": str},
80
+ required=["workspace_id"],
81
+ )
82
+ )
65
83
  registry.register(
66
84
  Tool(
67
85
  name="provision_link",
@@ -121,6 +139,24 @@ class MockAdapter(Adapter):
121
139
  items = list(_MockStore.connections.values())
122
140
  return ToolResult(ok=True, data={"connections": items, "count": len(items)})
123
141
 
142
+ async def _get_usage(self, workspace_id: str) -> ToolResult:
143
+ key = workspace_id.strip().lower()
144
+ if key not in _MockStore.workspaces and key != "demo":
145
+ return ToolResult(ok=False, error=f"Workspace '{key}' not found.")
146
+ return ToolResult(
147
+ ok=True,
148
+ data={"workspace_id": key, "api_calls": 42, "storage_mb": 128},
149
+ )
150
+
151
+ async def _get_subscription(self, workspace_id: str) -> ToolResult:
152
+ key = workspace_id.strip().lower()
153
+ if key not in _MockStore.workspaces and key != "demo":
154
+ return ToolResult(ok=False, error=f"Workspace '{key}' not found.")
155
+ return ToolResult(
156
+ ok=True,
157
+ data={"workspace_id": key, "plan": "pro", "status": "active"},
158
+ )
159
+
124
160
  async def _provision_link(
125
161
  self,
126
162
  site_a: str,