api-operator 0.10.0__tar.gz → 1.0.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 (74) hide show
  1. api_operator-1.0.0/.env.example +16 -0
  2. api_operator-1.0.0/CHANGELOG.md +75 -0
  3. {api_operator-0.10.0 → api_operator-1.0.0}/PKG-INFO +67 -52
  4. api_operator-1.0.0/README.md +184 -0
  5. api_operator-1.0.0/api_operator/__init__.py +37 -0
  6. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/adapters/base.py +4 -0
  7. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/adapters/openapi_generator.py +81 -4
  8. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/adapters/yaml_adapter.py +34 -0
  9. api_operator-1.0.0/api_operator/core/agent.py +550 -0
  10. api_operator-1.0.0/api_operator/core/audit.py +87 -0
  11. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/core/config.py +8 -0
  12. api_operator-1.0.0/api_operator/core/policy.py +232 -0
  13. api_operator-1.0.0/api_operator/core/quota.py +78 -0
  14. api_operator-1.0.0/api_operator/core/redaction.py +46 -0
  15. api_operator-1.0.0/api_operator/core/schemas.py +142 -0
  16. api_operator-1.0.0/api_operator/factory.py +62 -0
  17. api_operator-1.0.0/api_operator/rag/__init__.py +6 -0
  18. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/rag/indexer.py +2 -2
  19. api_operator-1.0.0/api_operator/rag/knowledge.py +129 -0
  20. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/server/app.py +18 -2
  21. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/server/cli.py +37 -5
  22. api_operator-1.0.0/docs/ROADMAP-vNEXT.md +482 -0
  23. api_operator-1.0.0/docs/audit.md +26 -0
  24. api_operator-1.0.0/docs/dry-run.md +30 -0
  25. api_operator-1.0.0/docs/knowledge.md +46 -0
  26. api_operator-1.0.0/docs/policy.md +42 -0
  27. api_operator-1.0.0/docs/public-api-inventory.md +56 -0
  28. api_operator-1.0.0/docs/quotas.md +25 -0
  29. api_operator-1.0.0/examples/jsonplaceholder-adapter/README.md +16 -0
  30. api_operator-1.0.0/examples/jsonplaceholder-adapter/adapter.yaml +57 -0
  31. api_operator-1.0.0/examples/jsonplaceholder-adapter/policy.yaml +21 -0
  32. api_operator-1.0.0/examples/tenant-kit-adapter/policy.yaml +24 -0
  33. {api_operator-0.10.0 → api_operator-1.0.0}/pyproject.toml +3 -2
  34. {api_operator-0.10.0 → api_operator-1.0.0}/tests/test_agent.py +1 -1
  35. api_operator-1.0.0/tests/test_audit.py +89 -0
  36. api_operator-1.0.0/tests/test_dry_run.py +112 -0
  37. api_operator-1.0.0/tests/test_knowledge.py +81 -0
  38. api_operator-1.0.0/tests/test_openapi_policy.py +149 -0
  39. api_operator-1.0.0/tests/test_policy.py +209 -0
  40. api_operator-1.0.0/tests/test_quota.py +55 -0
  41. api_operator-0.10.0/.env.example +0 -6
  42. api_operator-0.10.0/CHANGELOG.md +0 -39
  43. api_operator-0.10.0/README.md +0 -169
  44. api_operator-0.10.0/api_operator/__init__.py +0 -8
  45. api_operator-0.10.0/api_operator/core/agent.py +0 -161
  46. api_operator-0.10.0/api_operator/factory.py +0 -26
  47. {api_operator-0.10.0 → api_operator-1.0.0}/.github/workflows/tests.yml +0 -0
  48. {api_operator-0.10.0 → api_operator-1.0.0}/.gitignore +0 -0
  49. {api_operator-0.10.0 → api_operator-1.0.0}/Dockerfile +0 -0
  50. {api_operator-0.10.0 → api_operator-1.0.0}/LICENSE +0 -0
  51. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/adapters/__init__.py +0 -0
  52. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/adapters/mock.py +0 -0
  53. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/adapters/registry.py +0 -0
  54. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/adapters/yaml_spec.py +0 -0
  55. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/core/executor.py +0 -0
  56. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/core/formatters.py +0 -0
  57. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/core/guardrails.py +0 -0
  58. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/core/memory.py +0 -0
  59. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/core/planner.py +0 -0
  60. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/core/planner_openai.py +0 -0
  61. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/tools/base.py +0 -0
  62. {api_operator-0.10.0 → api_operator-1.0.0}/api_operator/tools/schema.py +0 -0
  63. {api_operator-0.10.0 → api_operator-1.0.0}/examples/tenant-kit-adapter/README.md +0 -0
  64. {api_operator-0.10.0 → api_operator-1.0.0}/examples/tenant-kit-adapter/adapter.yaml +0 -0
  65. {api_operator-0.10.0 → api_operator-1.0.0}/scripts/integration_tenant_kit.py +0 -0
  66. {api_operator-0.10.0 → api_operator-1.0.0}/tests/__init__.py +0 -0
  67. {api_operator-0.10.0 → api_operator-1.0.0}/tests/test_api.py +0 -0
  68. {api_operator-0.10.0 → api_operator-1.0.0}/tests/test_cli.py +0 -0
  69. {api_operator-0.10.0 → api_operator-1.0.0}/tests/test_core.py +0 -0
  70. {api_operator-0.10.0 → api_operator-1.0.0}/tests/test_formatters.py +0 -0
  71. {api_operator-0.10.0 → api_operator-1.0.0}/tests/test_integration_tenant_kit.py +0 -0
  72. {api_operator-0.10.0 → api_operator-1.0.0}/tests/test_mock_adapter.py +0 -0
  73. {api_operator-0.10.0 → api_operator-1.0.0}/tests/test_scenarios_e2e.py +0 -0
  74. {api_operator-0.10.0 → api_operator-1.0.0}/tests/test_yaml_adapter.py +0 -0
@@ -0,0 +1,16 @@
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_KNOWLEDGE_ENABLED=false
14
+ # api_operator_KNOWLEDGE_PATHS=docs/guide.md,README.md
15
+ # api_operator_KNOWLEDGE_LIMIT=3
16
+ # api_operator_CORS_ORIGINS=http://localhost:3000
@@ -0,0 +1,75 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ ## [1.0.0] - 2026-11-23
6
+
7
+ **Safe API Agent** production label. Builds on 0.11 foundation; additive and backward compatible for existing adapters.
8
+
9
+ ### Added
10
+
11
+ - Opt-in **keyword knowledge (L0)**: `API_OPERATOR_KNOWLEDGE_ENABLED` + `KNOWLEDGE_PATHS`
12
+ - Tenant-scoped doc isolation under `/tenants/{id}/`
13
+ - `docs/knowledge.md` (L1+ `rag` extra deferred to 1.1.0)
14
+
15
+ ### Changed
16
+
17
+ - Package version **1.0.0**; README / FastAPI metadata aligned
18
+
19
+ ## [0.11.0] - 2026-11-23
20
+
21
+ Foundation for **Safe API Agent** (see `docs/ROADMAP-vNEXT.md`). Opt-in; existing adapters keep working.
22
+
23
+ ### Added
24
+
25
+ - **Policy engine** (`policy.yaml`): allow / deny / confirm, deny lists, confirm lists, session `max_calls`, role/tenant rules
26
+ - **Dry-run**: CLI `--dry-run`, HTTP `dry_run=true`, `DryRunReport` + YAML `would_call` preview
27
+ - **Audit**: `AuditSink` protocol, JSONL / memory sinks, sensitive-field redaction
28
+ - **Quota hooks**: `QuotaGateway` + in-memory budget gateway (host owns real billing)
29
+ - Shared schemas: `PolicyDecision`, `QuotaReservation`, `AuditEvent`, `DryRunReport`
30
+ - Docs: `docs/policy.md`, `docs/dry-run.md`, `docs/audit.md`, `docs/quotas.md`, `docs/public-api-inventory.md`
31
+ - Example `examples/tenant-kit-adapter/policy.yaml`
32
+ - Example `examples/jsonplaceholder-adapter/` (public REST, non–tenant-kit)
33
+ - OpenAPI generator: tag-based `requires_ability`, write methods marked dangerous, draft `policy.yaml`
34
+ - `scaffold-adapter` also writes `policy.yaml`
35
+
36
+ ### Changed
37
+
38
+ - Agent `status` may be `deny` (additive) for policy/quota/ability rejection
39
+ - README reframed as **Safe API Agent**; version `0.11.0`
40
+
41
+ ## [0.10.0] - 2026-06-15
42
+
43
+ ### Added
44
+
45
+ - YAML adapter `connect_host` — route HTTP to an internal host (e.g. Docker `nginx`) while preserving logical `Host` headers for multi-tenant subdomains
46
+ - Optional CORS for `api-operator serve` via `API_OPERATOR_CORS_ORIGINS` (comma-separated)
47
+ - `Dockerfile` for containerized deployments
48
+ - `formatters.py` — human-readable tool success messages (no raw JSON in chat replies)
49
+ - Mock adapter tools: `get_usage`, `get_subscription`
50
+
51
+ ### Changed
52
+
53
+ - Mock planner — friendlier help text and NL patterns for tenant-kit flows
54
+ - FastAPI app version metadata updated to 0.10.0
55
+
56
+ ## [0.9.0] - 2026-06-14
57
+
58
+ Renamed to **`api-operator`** (GitHub + PyPI). PyPI blocks names starting with `operator` (stdlib conflict).
59
+
60
+ ### Added
61
+
62
+ - Core agent runtime: planning, guardrails, tool execution, session memory
63
+ - `mock` adapter for offline demos and tests
64
+ - `yaml` adapter — configure HTTP tools without Python
65
+ - OpenAPI scaffold CLI (`generate-from-openapi`, `scaffold-adapter`)
66
+ - CLI: `chat`, `demo`, `tools`, `serve`
67
+ - FastAPI server: `/health`, `/v1/adapters`, `/v1/tools`, `/v1/chat`
68
+ - Example adapter for [Laravel Tenant Kit](https://github.com/mohammedelkarsh/laravel-tenant-kit)
69
+ - Live integration script: `scripts/integration_tenant_kit.py`
70
+ - 69 unit tests; optional pytest integration marker
71
+
72
+ ### Notes
73
+
74
+ - Default planner is rule-based (`mock`); OpenAI planner is optional (`pip install api-operator[llm]`)
75
+ - Tenant team invites require a tenant-scoped Sanctum token (see example adapter README)
@@ -1,7 +1,7 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: api-operator
3
- Version: 0.10.0
4
- Summary: Standalone AI API Operator with pluggable adapters for multi-project APIs
3
+ Version: 1.0.0
4
+ Summary: Safe API Agent — run APIs with policy, quotas, audit, and optional knowledge
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==1.0.0
55
+ # optional OpenAI planner
56
+ pip install "api-operator[llm]==1.0.0"
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,53 @@ 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
+ | Optional keyword knowledge (L0) | Doc paths / per-tenant FAQ |
93
+ | `mock` + `yaml` adapters | Optional custom adapters |
94
+
95
+ No hard dependency on Laravel, Postgres, or vector DBs. Knowledge is **off** until you enable it ([docs/knowledge.md](docs/knowledge.md)).
96
+
97
+ ## Safe by default
98
+
99
+ 1. **Policy** — optional `policy.yaml` (allow / deny / confirm, session caps, roles)
100
+ 2. **Dry-run** — see the planned tool + upstream request without side effects
101
+ 3. **Audit** — JSONL / injectable sink; secrets redacted
102
+ 4. **Quota** — gate before execute; real billing stays in the host app
103
+
104
+ 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
105
 
78
106
  ## Build an adapter without Python
79
107
 
80
- ### Scaffold template
108
+ ### Scaffold
81
109
 
82
110
  ```bash
83
111
  api-operator scaffold-adapter my-api --output examples
112
+ # writes adapter.yaml + policy.yaml + README
84
113
  ```
85
114
 
86
115
  ### Generate from OpenAPI
87
116
 
117
+ Write methods (`POST`/`PATCH`/`PUT`/`DELETE`) are marked `dangerous`. Tag-based abilities are suggested. A draft `policy.yaml` is written next to the adapter.
118
+
88
119
  ```bash
89
120
  api-operator generate-from-openapi openapi.yaml \
90
121
  --output adapter.yaml \
@@ -92,9 +123,12 @@ api-operator generate-from-openapi openapi.yaml \
92
123
  --path-prefix /api
93
124
  ```
94
125
 
95
- ### Laravel Tenant Kit example
126
+ ### Examples
96
127
 
97
- See [`examples/tenant-kit-adapter/`](examples/tenant-kit-adapter/) — pairs with [laravel-tenant-kit](https://github.com/mohammedelkarsh/laravel-tenant-kit).
128
+ | Example | Purpose |
129
+ |---------|---------|
130
+ | [`examples/tenant-kit-adapter/`](examples/tenant-kit-adapter/) | Laravel Tenant Kit |
131
+ | [`examples/jsonplaceholder-adapter/`](examples/jsonplaceholder-adapter/) | Public REST demo |
98
132
 
99
133
  ```bash
100
134
  export TENANT_KIT_API_TOKEN="your-sanctum-token"
@@ -120,12 +154,14 @@ tools:
120
154
  description: List items
121
155
  method: GET
122
156
  path: /api/items
157
+ requires_ability: items:read
123
158
 
124
159
  - name: create_item
125
160
  description: Create item
126
161
  method: POST
127
162
  path: /api/items
128
163
  dangerous: true
164
+ requires_ability: items:write
129
165
  parameters:
130
166
  title:
131
167
  type: string
@@ -134,18 +170,7 @@ tools:
134
170
  title: "{title}"
135
171
  ```
136
172
 
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
- ```
173
+ Optional sibling `policy.yaml` loads automatically when you pass that adapter path.
149
174
 
150
175
  ## HTTP server
151
176
 
@@ -160,45 +185,35 @@ POST /v1/chat
160
185
  "config_path": "examples/tenant-kit-adapter/adapter.yaml",
161
186
  "adapter_config": { "token": "YOUR_TOKEN" },
162
187
  "message": "list workspaces",
163
- "abilities": ["workspaces:read"]
188
+ "abilities": ["workspaces:read"],
189
+ "dry_run": false
164
190
  }
165
191
  ```
166
192
 
167
- ## Integration test (Tenant Kit)
168
-
169
- With [Tenant Kit](https://github.com/mohammedelkarsh/laravel-tenant-kit) running:
193
+ ## Tests
170
194
 
171
195
  ```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
196
+ pytest -q
175
197
  ```
176
198
 
177
- Optional pytest marker (requires env vars):
199
+ Live Tenant Kit (optional):
178
200
 
179
201
  ```bash
180
- export TENANT_KIT_BASE_URL=http://laravel-tenant-kit.test
181
- export TENANT_KIT_API_TOKEN=your-token
202
+ python scripts/integration_tenant_kit.py
182
203
  pytest -m integration -q
183
204
  ```
184
205
 
185
- ## Tests
186
-
187
- ```bash
188
- pytest -q
189
- ```
190
-
191
206
  ## Configuration
192
207
 
193
- Copy `.env.example` to `.env` for local defaults (`api_operator_PLANNER`, port, etc.).
208
+ 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
209
 
195
210
  ## Architecture
196
211
 
197
212
  ```
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, …)
213
+ api-operator (Safe API Agent) your hosts
214
+ ├── plan → policy → quota → act ├── adapter.yaml + policy.yaml
215
+ ├── dry-run + audit hooks ├── OpenAPI
216
+ └── mock / yaml adapters └── Laravel / any REST API
202
217
  ```
203
218
 
204
219
  ## License
@@ -0,0 +1,184 @@
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==1.0.0
18
+ # optional OpenAI planner
19
+ pip install "api-operator[llm]==1.0.0"
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
+ | Optional keyword knowledge (L0) | Doc paths / per-tenant FAQ |
56
+ | `mock` + `yaml` adapters | Optional custom adapters |
57
+
58
+ No hard dependency on Laravel, Postgres, or vector DBs. Knowledge is **off** until you enable it ([docs/knowledge.md](docs/knowledge.md)).
59
+
60
+ ## Safe by default
61
+
62
+ 1. **Policy** — optional `policy.yaml` (allow / deny / confirm, session caps, roles)
63
+ 2. **Dry-run** — see the planned tool + upstream request without side effects
64
+ 3. **Audit** — JSONL / injectable sink; secrets redacted
65
+ 4. **Quota** — gate before execute; real billing stays in the host app
66
+
67
+ Docs: [policy](docs/policy.md) · [dry-run](docs/dry-run.md) · [audit](docs/audit.md) · [quotas](docs/quotas.md) · [roadmap](docs/ROADMAP-vNEXT.md)
68
+
69
+ ## Build an adapter without Python
70
+
71
+ ### Scaffold
72
+
73
+ ```bash
74
+ api-operator scaffold-adapter my-api --output examples
75
+ # writes adapter.yaml + policy.yaml + README
76
+ ```
77
+
78
+ ### Generate from OpenAPI
79
+
80
+ Write methods (`POST`/`PATCH`/`PUT`/`DELETE`) are marked `dangerous`. Tag-based abilities are suggested. A draft `policy.yaml` is written next to the adapter.
81
+
82
+ ```bash
83
+ api-operator generate-from-openapi openapi.yaml \
84
+ --output adapter.yaml \
85
+ --base-url http://api.example.test \
86
+ --path-prefix /api
87
+ ```
88
+
89
+ ### Examples
90
+
91
+ | Example | Purpose |
92
+ |---------|---------|
93
+ | [`examples/tenant-kit-adapter/`](examples/tenant-kit-adapter/) | Laravel Tenant Kit |
94
+ | [`examples/jsonplaceholder-adapter/`](examples/jsonplaceholder-adapter/) | Public REST demo |
95
+
96
+ ```bash
97
+ export TENANT_KIT_API_TOKEN="your-sanctum-token"
98
+ api-operator chat \
99
+ --adapter yaml \
100
+ --config examples/tenant-kit-adapter/adapter.yaml \
101
+ --base-url http://laravel-tenant-kit.test
102
+ ```
103
+
104
+ ## adapter.yaml (minimal)
105
+
106
+ ```yaml
107
+ name: my_project
108
+ description: My API adapter
109
+ base_url: http://api.example.test
110
+
111
+ auth:
112
+ type: bearer
113
+ env_token: MY_PROJECT_API_TOKEN
114
+
115
+ tools:
116
+ - name: list_items
117
+ description: List items
118
+ method: GET
119
+ path: /api/items
120
+ requires_ability: items:read
121
+
122
+ - name: create_item
123
+ description: Create item
124
+ method: POST
125
+ path: /api/items
126
+ dangerous: true
127
+ requires_ability: items:write
128
+ parameters:
129
+ title:
130
+ type: string
131
+ required: true
132
+ body:
133
+ title: "{title}"
134
+ ```
135
+
136
+ Optional sibling `policy.yaml` loads automatically when you pass that adapter path.
137
+
138
+ ## HTTP server
139
+
140
+ ```bash
141
+ api-operator serve --port 8100
142
+ ```
143
+
144
+ ```json
145
+ POST /v1/chat
146
+ {
147
+ "adapter": "yaml",
148
+ "config_path": "examples/tenant-kit-adapter/adapter.yaml",
149
+ "adapter_config": { "token": "YOUR_TOKEN" },
150
+ "message": "list workspaces",
151
+ "abilities": ["workspaces:read"],
152
+ "dry_run": false
153
+ }
154
+ ```
155
+
156
+ ## Tests
157
+
158
+ ```bash
159
+ pytest -q
160
+ ```
161
+
162
+ Live Tenant Kit (optional):
163
+
164
+ ```bash
165
+ python scripts/integration_tenant_kit.py
166
+ pytest -m integration -q
167
+ ```
168
+
169
+ ## Configuration
170
+
171
+ 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`.
172
+
173
+ ## Architecture
174
+
175
+ ```
176
+ api-operator (Safe API Agent) your hosts
177
+ ├── plan → policy → quota → act ├── adapter.yaml + policy.yaml
178
+ ├── dry-run + audit hooks ├── OpenAPI
179
+ └── mock / yaml adapters └── Laravel / any REST API
180
+ ```
181
+
182
+ ## License
183
+
184
+ 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__ = "1.0.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