@aporthq/aport-agent-guardrails 1.0.8
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.
- package/LICENSE +217 -0
- package/README.md +481 -0
- package/bin/agent-guardrails +133 -0
- package/bin/aport-create-passport.sh +444 -0
- package/bin/aport-cursor-hook.sh +90 -0
- package/bin/aport-guardrail-api.sh +108 -0
- package/bin/aport-guardrail-bash.sh +394 -0
- package/bin/aport-guardrail-v2.sh +5 -0
- package/bin/aport-guardrail.sh +5 -0
- package/bin/aport-resolve-paths.sh +71 -0
- package/bin/aport-status.sh +276 -0
- package/bin/frameworks/crewai.sh +49 -0
- package/bin/frameworks/cursor.sh +95 -0
- package/bin/frameworks/langchain.sh +48 -0
- package/bin/frameworks/n8n.sh +36 -0
- package/bin/frameworks/openclaw.sh +19 -0
- package/bin/lib/allowlist.sh +18 -0
- package/bin/lib/common.sh +28 -0
- package/bin/lib/config.sh +46 -0
- package/bin/lib/constants.sh +232 -0
- package/bin/lib/detect.sh +65 -0
- package/bin/lib/error.sh +269 -0
- package/bin/lib/passport.sh +19 -0
- package/bin/lib/templates/.gitkeep +1 -0
- package/bin/lib/templates/config.yaml +6 -0
- package/bin/lib/validation.sh +206 -0
- package/bin/openclaw +660 -0
- package/docs/ADDING_A_FRAMEWORK.md +87 -0
- package/docs/AGENTS.md.example +40 -0
- package/docs/CODE_REVIEW.md +192 -0
- package/docs/DEPLOYMENT_READINESS.md +81 -0
- package/docs/FAQ_SECURITY_SCANNERS.md +373 -0
- package/docs/FRAMEWORK_ROADMAP.md +41 -0
- package/docs/HOSTED_PASSPORT_SETUP.md +362 -0
- package/docs/IMPLEMENTING_YOUR_OWN_EVALUATOR.md +433 -0
- package/docs/OPENCLAW_COMPATIBILITY.md +73 -0
- package/docs/OPENCLAW_LOCAL_INTEGRATION.md +596 -0
- package/docs/OPENCLAW_TOOLS_AND_POLICIES.md +54 -0
- package/docs/QUICKSTART.md +470 -0
- package/docs/QUICKSTART_OPENCLAW_PLUGIN.md +470 -0
- package/docs/README.md +28 -0
- package/docs/RELEASE.md +87 -0
- package/docs/REPO_LAYOUT.md +47 -0
- package/docs/SKILLS_ECOSYSTEM_ANALYSIS_FEB17.md +1260 -0
- package/docs/TOOL_POLICY_MAPPING.md +46 -0
- package/docs/UPGRADE.md +46 -0
- package/docs/VERIFICATION_METHODS.md +97 -0
- package/docs/assets/README.md +8 -0
- package/docs/assets/porter.svg +54 -0
- package/docs/development/ERROR_CODES.md +616 -0
- package/docs/frameworks/GITHUB_ISSUE_PROPOSALS.md +1105 -0
- package/docs/frameworks/crewai.md +114 -0
- package/docs/frameworks/cursor.md +159 -0
- package/docs/frameworks/langchain.md +72 -0
- package/docs/frameworks/n8n.md +40 -0
- package/docs/frameworks/openclaw.md +40 -0
- package/docs/launch/ADD_APORT_AWESOME_LISTS_INSTRUCTIONS.md +146 -0
- package/docs/launch/ANNOUNCEMENT_GUIDE.md +266 -0
- package/docs/launch/AWESOME_REPOS.md +53 -0
- package/docs/launch/CURSOR_VSCODE_HOOKS_RESEARCH.md +77 -0
- package/docs/launch/DEMO_TERMINAL_OUTPUT.txt +48 -0
- package/docs/launch/DRY_AND_PLAN_CHECKLIST.md +47 -0
- package/docs/launch/EVIDENCE_README.md +61 -0
- package/docs/launch/EVIDENCE_TERMINAL_CAPTURE.txt +10 -0
- package/docs/launch/FRAMEWORK_SUPPORT_PLAN.md +1640 -0
- package/docs/launch/LAUNCH_READINESS_CHECKLIST.md +237 -0
- package/docs/launch/LAUNCH_STRATEGY_SUMMARY.md +464 -0
- package/docs/launch/OPENCLAW_FEEDBACK_AND_FIXES.md +85 -0
- package/docs/launch/POST_1_VALENTINE_IMPROVED.md +233 -0
- package/docs/launch/POST_2_GUARDRAIL_IMPROVED.md +369 -0
- package/docs/launch/PRE_LAUNCH_FIXES.md +766 -0
- package/docs/launch/QUICK_LAUNCH_CHECKLIST.md +400 -0
- package/docs/launch/READINESS_SUMMARY.md +262 -0
- package/docs/launch/README.md +68 -0
- package/docs/launch/USER_STORIES.md +327 -0
- package/docs/launch/scripts/add-aport-awesome-pr.sh +69 -0
- package/docs/operations/MONITORING.md +588 -0
- package/docs/reviews/2026-02-18-staff-review.md +268 -0
- package/extensions/openclaw-aport/README.md +415 -0
- package/extensions/openclaw-aport/index.js +625 -0
- package/extensions/openclaw-aport/openclaw-aport.js +7 -0
- package/extensions/openclaw-aport/openclaw.plugin.json +46 -0
- package/extensions/openclaw-aport/package.json +36 -0
- package/extensions/openclaw-aport/test.js +307 -0
- package/external/aport-policies/README.md +363 -0
- package/external/aport-policies/agent.session.create.v1/README.md +345 -0
- package/external/aport-policies/agent.session.create.v1/policy.json +162 -0
- package/external/aport-policies/agent.tool.register.v1/README.md +361 -0
- package/external/aport-policies/agent.tool.register.v1/policy.json +172 -0
- package/external/aport-policies/code.release.publish.v1/README.md +51 -0
- package/external/aport-policies/code.release.publish.v1/policy.json +121 -0
- package/external/aport-policies/code.repository.merge.v1/README.md +287 -0
- package/external/aport-policies/code.repository.merge.v1/express.example.js +332 -0
- package/external/aport-policies/code.repository.merge.v1/fastapi.example.py +370 -0
- package/external/aport-policies/code.repository.merge.v1/policy.json +162 -0
- package/external/aport-policies/data.export.create.v1/README.md +226 -0
- package/external/aport-policies/data.export.create.v1/express.example.js +172 -0
- package/external/aport-policies/data.export.create.v1/fastapi.example.py +165 -0
- package/external/aport-policies/data.export.create.v1/policy.json +133 -0
- package/external/aport-policies/data.report.ingest.v1/README.md +134 -0
- package/external/aport-policies/data.report.ingest.v1/express.example.js +105 -0
- package/external/aport-policies/data.report.ingest.v1/minimal-example.js +68 -0
- package/external/aport-policies/data.report.ingest.v1/policy.json +174 -0
- package/external/aport-policies/finance.crypto.trade.v1/README.md +146 -0
- package/external/aport-policies/finance.crypto.trade.v1/express.example.js +109 -0
- package/external/aport-policies/finance.crypto.trade.v1/minimal-example.js +65 -0
- package/external/aport-policies/finance.crypto.trade.v1/policy.json +176 -0
- package/external/aport-policies/finance.payment.charge.v1/README.md +326 -0
- package/external/aport-policies/finance.payment.charge.v1/express.example.js +250 -0
- package/external/aport-policies/finance.payment.charge.v1/fastapi.example.py +227 -0
- package/external/aport-policies/finance.payment.charge.v1/minimal-example.js +64 -0
- package/external/aport-policies/finance.payment.charge.v1/policy.json +224 -0
- package/external/aport-policies/finance.payment.charge.v1/tests/contexts.jsonl +12 -0
- package/external/aport-policies/finance.payment.charge.v1/tests/expected.jsonl +12 -0
- package/external/aport-policies/finance.payment.charge.v1/tests/passport.instance.json +42 -0
- package/external/aport-policies/finance.payment.charge.v1/tests/passport.template.json +40 -0
- package/external/aport-policies/finance.payment.charge.v1/tests/payments-charge-policy.test.js +817 -0
- package/external/aport-policies/finance.payment.charge.v1/tests/test_payments_charge_policy.py +486 -0
- package/external/aport-policies/finance.payment.payout.v1/README.md +78 -0
- package/external/aport-policies/finance.payment.payout.v1/policy.json +181 -0
- package/external/aport-policies/finance.payment.refund.v1/README.md +275 -0
- package/external/aport-policies/finance.payment.refund.v1/express.example.js +167 -0
- package/external/aport-policies/finance.payment.refund.v1/fastapi.example.py +136 -0
- package/external/aport-policies/finance.payment.refund.v1/minimal-example.js +183 -0
- package/external/aport-policies/finance.payment.refund.v1/policy.json +216 -0
- package/external/aport-policies/finance.payment.refund.v1/tests/refunds-policy.test.js +924 -0
- package/external/aport-policies/finance.payment.refund.v1/tests/test_refunds_policy.py +778 -0
- package/external/aport-policies/finance.transaction.execute.v1/README.md +309 -0
- package/external/aport-policies/finance.transaction.execute.v1/express.example.js +261 -0
- package/external/aport-policies/finance.transaction.execute.v1/fastapi.example.py +231 -0
- package/external/aport-policies/finance.transaction.execute.v1/minimal-example.js +78 -0
- package/external/aport-policies/finance.transaction.execute.v1/policy.json +189 -0
- package/external/aport-policies/finance.transaction.execute.v1/tests/contexts.jsonl +12 -0
- package/external/aport-policies/finance.transaction.execute.v1/tests/expected.jsonl +12 -0
- package/external/aport-policies/finance.transaction.execute.v1/tests/passport.instance.json +42 -0
- package/external/aport-policies/finance.transaction.execute.v1/tests/passport.template.json +42 -0
- package/external/aport-policies/finance.transaction.execute.v1/tests/test_transactions_policy.py +214 -0
- package/external/aport-policies/finance.transaction.execute.v1/tests/transactions-policy.test.js +306 -0
- package/external/aport-policies/governance.data.access.v1/README.md +292 -0
- package/external/aport-policies/governance.data.access.v1/express.example.js +321 -0
- package/external/aport-policies/governance.data.access.v1/fastapi.example.py +279 -0
- package/external/aport-policies/governance.data.access.v1/minimal-example.js +65 -0
- package/external/aport-policies/governance.data.access.v1/policy.json +208 -0
- package/external/aport-policies/governance.data.access.v1/tests/contexts.jsonl +12 -0
- package/external/aport-policies/governance.data.access.v1/tests/data-access-policy.test.js +308 -0
- package/external/aport-policies/governance.data.access.v1/tests/expected.jsonl +12 -0
- package/external/aport-policies/governance.data.access.v1/tests/passport.instance.json +56 -0
- package/external/aport-policies/governance.data.access.v1/tests/passport.template.json +56 -0
- package/external/aport-policies/governance.data.access.v1/tests/test_data_access_policy.py +214 -0
- package/external/aport-policies/legal.contract.review.v1/README.md +109 -0
- package/external/aport-policies/legal.contract.review.v1/policy.json +378 -0
- package/external/aport-policies/legal.contract.review.v1/tests/legal-contract-review-policy.test.js +609 -0
- package/external/aport-policies/legal.contract.review.v1/tests/passport.template.json +49 -0
- package/external/aport-policies/mcp.tool.execute.v1/README.md +301 -0
- package/external/aport-policies/mcp.tool.execute.v1/policy.json +141 -0
- package/external/aport-policies/messaging.message.send.v1/README.md +230 -0
- package/external/aport-policies/messaging.message.send.v1/express.example.js +183 -0
- package/external/aport-policies/messaging.message.send.v1/fastapi.example.py +193 -0
- package/external/aport-policies/messaging.message.send.v1/policy.json +144 -0
- package/external/aport-policies/policy-template.json +107 -0
- package/external/aport-policies/system.command.execute.v1/README.md +275 -0
- package/external/aport-policies/system.command.execute.v1/policy.json +146 -0
- package/external/aport-spec/CONTRIBUTING.md +273 -0
- package/external/aport-spec/LICENSE +21 -0
- package/external/aport-spec/README.md +168 -0
- package/external/aport-spec/conformance/README.md +294 -0
- package/external/aport-spec/conformance/cases/data.export.v1/contexts/allow_users.json +6 -0
- package/external/aport-spec/conformance/cases/data.export.v1/contexts/deny_pii.json +6 -0
- package/external/aport-spec/conformance/cases/data.export.v1/expected/allow_users.decision.json +19 -0
- package/external/aport-spec/conformance/cases/data.export.v1/expected/deny_pii.decision.json +19 -0
- package/external/aport-spec/conformance/cases/data.export.v1/passports/template.json +29 -0
- package/external/aport-spec/conformance/cases/payments.refunds.v1/contexts/allow_50usd.json +9 -0
- package/external/aport-spec/conformance/cases/payments.refunds.v1/contexts/deny_150usd.json +9 -0
- package/external/aport-spec/conformance/cases/payments.refunds.v1/contexts/deny_currency.json +9 -0
- package/external/aport-spec/conformance/cases/payments.refunds.v1/expected/allow_50usd.decision.json +19 -0
- package/external/aport-spec/conformance/cases/payments.refunds.v1/expected/deny_150usd.decision.json +19 -0
- package/external/aport-spec/conformance/cases/payments.refunds.v1/expected/deny_currency.decision.json +19 -0
- package/external/aport-spec/conformance/cases/payments.refunds.v1/passports/template.json +42 -0
- package/external/aport-spec/conformance/package.json +44 -0
- package/external/aport-spec/conformance/pnpm-lock.yaml +642 -0
- package/external/aport-spec/conformance/src/cases.ts +371 -0
- package/external/aport-spec/conformance/src/ed25519.ts +167 -0
- package/external/aport-spec/conformance/src/jcs.ts +85 -0
- package/external/aport-spec/conformance/src/runner.ts +533 -0
- package/external/aport-spec/conformance/src/validators.ts +185 -0
- package/external/aport-spec/conformance/test-runner.js +315 -0
- package/external/aport-spec/conformance/tsconfig.json +21 -0
- package/external/aport-spec/error-schema.json +192 -0
- package/external/aport-spec/index.json +12 -0
- package/external/aport-spec/integrations/clawmoat/README.md +12 -0
- package/external/aport-spec/integrations/shield/README.md +245 -0
- package/external/aport-spec/integrations/shield/adapters/index.js +116 -0
- package/external/aport-spec/integrations/shield/adapters/system-command-execute.js +133 -0
- package/external/aport-spec/integrations/shield/test/README.md +58 -0
- package/external/aport-spec/integrations/shield/test/shield.md +40 -0
- package/external/aport-spec/integrations/shield/test/test-shield-to-verify.js +274 -0
- package/external/aport-spec/metrics-schema.json +504 -0
- package/external/aport-spec/oap/CHANGELOG.md +54 -0
- package/external/aport-spec/oap/VERSION.md +40 -0
- package/external/aport-spec/oap/capability-registry.md +229 -0
- package/external/aport-spec/oap/conformance.md +257 -0
- package/external/aport-spec/oap/decision-schema.json +114 -0
- package/external/aport-spec/oap/examples/context.refund.usd.50.json +9 -0
- package/external/aport-spec/oap/examples/decision.allow.sample.json +20 -0
- package/external/aport-spec/oap/examples/decision.deny.sample.json +23 -0
- package/external/aport-spec/oap/examples/passport.instance.v1.json +50 -0
- package/external/aport-spec/oap/examples/passport.template.v1.json +71 -0
- package/external/aport-spec/oap/oap-spec.md +426 -0
- package/external/aport-spec/oap/passport-schema.json +396 -0
- package/external/aport-spec/oap/security.md +213 -0
- package/external/aport-spec/oap/vc/context-oap-v1.jsonld +137 -0
- package/external/aport-spec/oap/vc/examples/oap-decision-vc.json +37 -0
- package/external/aport-spec/oap/vc/examples/oap-passport-vc.json +68 -0
- package/external/aport-spec/oap/vc/tools/INTEGRATION.md +375 -0
- package/external/aport-spec/oap/vc/tools/README.md +278 -0
- package/external/aport-spec/oap/vc/tools/examples/decision-to-vc.js +66 -0
- package/external/aport-spec/oap/vc/tools/examples/passport-to-vc.js +83 -0
- package/external/aport-spec/oap/vc/tools/examples/vc-to-decision.js +77 -0
- package/external/aport-spec/oap/vc/tools/examples/vc-to-passport.js +94 -0
- package/external/aport-spec/oap/vc/tools/package.json +38 -0
- package/external/aport-spec/oap/vc/tools/pnpm-lock.yaml +472 -0
- package/external/aport-spec/oap/vc/tools/src/cli.ts +226 -0
- package/external/aport-spec/oap/vc/tools/src/crypto-utils.ts +427 -0
- package/external/aport-spec/oap/vc/tools/src/index.ts +653 -0
- package/external/aport-spec/oap/vc/tools/src/test.ts +148 -0
- package/external/aport-spec/oap/vc/tools/src/vp.ts +382 -0
- package/external/aport-spec/oap/vc/tools/test-simple.js +214 -0
- package/external/aport-spec/oap/vc/tools/tsconfig.json +19 -0
- package/external/aport-spec/oap/vc/vc-mapping.md +443 -0
- package/external/aport-spec/passport-schema.json +586 -0
- package/external/aport-spec/rate-limiting.md +136 -0
- package/external/aport-spec/transport-profile.md +325 -0
- package/external/aport-spec/webhook-spec.md +314 -0
- package/package.json +70 -0
- package/skills/aport-agent-guardrail/SKILL.md +314 -0
- package/src/evaluator.js +252 -0
- package/src/server/index.js +72 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
# 🛡️ APort Policy Packs
|
|
2
|
+
|
|
3
|
+
> **Open Agent Passport (OAP) v1.0 compliant policy definitions for AI agent governance**
|
|
4
|
+
|
|
5
|
+
This directory contains production-ready policy packs that implement the [Open Agent Passport (OAP) v1.0 specification](https://github.com/aporthq/aport-spec) for real-time AI agent authorization and policy enforcement.
|
|
6
|
+
|
|
7
|
+
## 🎯 What Are Policy Packs?
|
|
8
|
+
|
|
9
|
+
Policy packs are **pre-built, OAP-compliant policy definitions** that provide instant governance for your most sensitive AI agent operations. Each pack includes:
|
|
10
|
+
|
|
11
|
+
- **📋 Standardized Rules** - OAP v1.0 compliant evaluation logic
|
|
12
|
+
- **🔐 Capability Requirements** - What agents need to perform actions
|
|
13
|
+
- **⚡ Real-time Enforcement** - Sub-100ms policy decisions
|
|
14
|
+
- **🛡️ Security Controls** - Multi-level assurance and limits
|
|
15
|
+
- **📊 Audit Trail** - Cryptographically signed decisions
|
|
16
|
+
|
|
17
|
+
## 🚀 Available Policy Packs
|
|
18
|
+
|
|
19
|
+
### 🤖 **Agent Management**
|
|
20
|
+
|
|
21
|
+
| Policy Pack | Capability | Min Assurance | Key Features |
|
|
22
|
+
|-------------|------------|---------------|--------------|
|
|
23
|
+
| **`agent.session.create.v1`** | `agent.session.create` | L0 | Session limits, duration restrictions, concurrent session controls |
|
|
24
|
+
| **`agent.tool.register.v1`** | `agent.tool.register` | L0 | Tool naming conventions, capability declarations, registration limits |
|
|
25
|
+
|
|
26
|
+
### 💳 **Finance & Payments**
|
|
27
|
+
|
|
28
|
+
| Policy Pack | Capability | Min Assurance | Key Features |
|
|
29
|
+
|-------------|------------|---------------|--------------|
|
|
30
|
+
| **`finance.payment.charge.v1`** | `payments.charge` | L2 | Multi-currency limits, merchant allowlists, category blocking |
|
|
31
|
+
| **`finance.payment.refund.v1`** | `finance.payment.refund` | L2 | Cross-currency denial, reason codes, order validation |
|
|
32
|
+
| **`finance.payment.payout.v1`** | `payments.payout` | L3 | Per-currency caps, destination restrictions, compliance requirements |
|
|
33
|
+
| **`finance.transaction.execute.v1`** | `finance.transaction` | L3 | Transaction limits, risk scoring, compliance checks |
|
|
34
|
+
| **`finance.crypto.trade.v1`** | `finance.crypto.trade` | L3 | Crypto trading limits, exchange validation, volatility controls |
|
|
35
|
+
|
|
36
|
+
### 📊 **Data & Privacy**
|
|
37
|
+
|
|
38
|
+
| Policy Pack | Capability | Min Assurance | Key Features |
|
|
39
|
+
|-------------|------------|---------------|--------------|
|
|
40
|
+
| **`data.export.create.v1`** | `data.export` | L1 | Row limits, PII handling, format validation |
|
|
41
|
+
| **`data.report.ingest.v1`** | `data.report.ingest` | L2 | Data quality checks, schema validation, rate limiting |
|
|
42
|
+
| **`governance.data.access.v1`** | `data.access` | L3 | Access controls, data classification, audit logging |
|
|
43
|
+
|
|
44
|
+
### 🔀 **Code & Infrastructure**
|
|
45
|
+
|
|
46
|
+
| Policy Pack | Capability | Min Assurance | Key Features |
|
|
47
|
+
|-------------|------------|---------------|--------------|
|
|
48
|
+
| **`code.repository.merge.v1`** | `repo.merge`, `repo.pr.create` | L2 | PR limits, path restrictions, review requirements |
|
|
49
|
+
| **`code.release.publish.v1`** | `release` | L3 | Release validation, environment checks, approval workflows |
|
|
50
|
+
|
|
51
|
+
### ⚙️ **System & Tools**
|
|
52
|
+
|
|
53
|
+
| Policy Pack | Capability | Min Assurance | Key Features |
|
|
54
|
+
|-------------|------------|---------------|--------------|
|
|
55
|
+
| **`system.command.execute.v1`** | `system.command.execute` | L0 | Command allowlists, blocked patterns, execution time limits |
|
|
56
|
+
| **`mcp.tool.execute.v1`** | `mcp.tool.execute` | L0 | Server allowlists, tool restrictions, parameter validation |
|
|
57
|
+
|
|
58
|
+
### 💬 **Communication**
|
|
59
|
+
|
|
60
|
+
| Policy Pack | Capability | Min Assurance | Key Features |
|
|
61
|
+
|-------------|------------|---------------|--------------|
|
|
62
|
+
| **`messaging.message.send.v1`** | `messaging.send` | L0 | Rate limiting, channel restrictions, mention policies |
|
|
63
|
+
|
|
64
|
+
### ⚖️ **Legal & Compliance**
|
|
65
|
+
|
|
66
|
+
| Policy Pack | Capability | Min Assurance | Key Features |
|
|
67
|
+
|-------------|------------|---------------|--------------|
|
|
68
|
+
| **`legal.contract.review.v1`** | `legal.contract.review` | L3 | Firm-specific guardrails, privilege protection, attorney supervision |
|
|
69
|
+
|
|
70
|
+
## 🏗️ Policy Pack Structure
|
|
71
|
+
|
|
72
|
+
All policy packs follow the [OAP v1.0 specification](https://github.com/aporthq/aport-spec) and include:
|
|
73
|
+
|
|
74
|
+
### **Core OAP Fields**
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"id": "finance.payment.charge.v1",
|
|
78
|
+
"name": "Payment Charge Policy",
|
|
79
|
+
"description": "Pre-action governance for agent-initiated payments...",
|
|
80
|
+
"version": "1.0.0",
|
|
81
|
+
"status": "active",
|
|
82
|
+
"requires_capabilities": ["payments.charge"],
|
|
83
|
+
"min_assurance": "L2"
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### **OAP Compliance Features**
|
|
88
|
+
- ✅ **Standardized Error Codes** - Uses `oap.*` error codes
|
|
89
|
+
- ✅ **JSON Schema Validation** - Full context validation via `required_context`
|
|
90
|
+
- ✅ **Nested Limits Structure** - `limits.{capability}.*` format
|
|
91
|
+
- ✅ **Capability-based Authorization** - Proper capability checking
|
|
92
|
+
- ✅ **Assurance Level Validation** - Dynamic assurance requirements
|
|
93
|
+
- ✅ **Idempotency Support** - Duplicate prevention
|
|
94
|
+
- ✅ **Cache Configuration** - TTL and invalidation settings
|
|
95
|
+
|
|
96
|
+
### **Evaluation Rules**
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"evaluation_rules_version": "1.0",
|
|
100
|
+
"evaluation_rules": [
|
|
101
|
+
{
|
|
102
|
+
"name": "command_allowlist",
|
|
103
|
+
"type": "expression",
|
|
104
|
+
"condition": "limits.allowed_commands.includes('*') || limits.allowed_commands.includes(context.command)",
|
|
105
|
+
"deny_code": "oap.command_not_allowed",
|
|
106
|
+
"description": "Command must be in allowed list"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"name": "blocked_patterns",
|
|
110
|
+
"type": "custom_validator",
|
|
111
|
+
"validator": "validateBlockedPatterns",
|
|
112
|
+
"deny_code": "oap.blocked_pattern",
|
|
113
|
+
"description": "Command must not contain blocked patterns"
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Note**: Evaluation rules support two types:
|
|
120
|
+
- **`expression`**: Uses the `condition` field with JavaScript-like expressions
|
|
121
|
+
- **`custom_validator`**: Uses the `validator` field to reference custom validation functions
|
|
122
|
+
|
|
123
|
+
## 🛠️ Implementation Examples
|
|
124
|
+
|
|
125
|
+
### Express.js Middleware
|
|
126
|
+
```javascript
|
|
127
|
+
const { requirePolicy } = require("@aporthq/middleware-express");
|
|
128
|
+
|
|
129
|
+
// Apply payment charge policy
|
|
130
|
+
app.post("/api/charges",
|
|
131
|
+
requirePolicy("finance.payment.charge.v1"),
|
|
132
|
+
async (req, res) => {
|
|
133
|
+
// Policy already verified! Check specific limits
|
|
134
|
+
const passport = req.policyResult.passport;
|
|
135
|
+
|
|
136
|
+
if (req.body.amount > passport.limits.payments.charge.currency_limits.USD.max_per_tx) {
|
|
137
|
+
return res.status(403).json({
|
|
138
|
+
error: "Charge exceeds limit",
|
|
139
|
+
requested: req.body.amount,
|
|
140
|
+
limit: passport.limits.payments.charge.currency_limits.USD.max_per_tx
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Process charge safely
|
|
145
|
+
const charge = await stripe.charges.create(req.body);
|
|
146
|
+
res.json({ success: true, charge });
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### FastAPI Middleware
|
|
152
|
+
```python
|
|
153
|
+
from aport.middleware import require_policy
|
|
154
|
+
|
|
155
|
+
@app.post("/api/charges")
|
|
156
|
+
@require_policy("finance.payment.charge.v1")
|
|
157
|
+
async def create_charge(request: Request, charge_data: dict):
|
|
158
|
+
passport = request.state.policy_result.passport
|
|
159
|
+
|
|
160
|
+
# Check currency limits
|
|
161
|
+
currency_limits = passport.limits["payments.charge"]["currency_limits"]
|
|
162
|
+
if charge_data["amount"] > currency_limits[charge_data["currency"]]["max_per_tx"]:
|
|
163
|
+
raise HTTPException(403, {
|
|
164
|
+
"error": "Charge exceeds limit",
|
|
165
|
+
"requested": charge_data["amount"],
|
|
166
|
+
"limit": currency_limits[charge_data["currency"]]["max_per_tx"]
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
# Process charge safely
|
|
170
|
+
return {"success": True, "charge_id": f"chg_{int(time.time())}"}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### GitHub Actions Integration
|
|
174
|
+
```yaml
|
|
175
|
+
name: APort Verify PR
|
|
176
|
+
on: [pull_request]
|
|
177
|
+
|
|
178
|
+
jobs:
|
|
179
|
+
verify:
|
|
180
|
+
runs-on: ubuntu-latest
|
|
181
|
+
steps:
|
|
182
|
+
- uses: actions/checkout@v4
|
|
183
|
+
- name: Verify via APort
|
|
184
|
+
run: |
|
|
185
|
+
curl -s -X POST "https://api.aport.io/api/verify/policy/code.repository.merge.v1" \
|
|
186
|
+
-H "Content-Type: application/json" \
|
|
187
|
+
-d '{
|
|
188
|
+
"agent_id": "${{ secrets.APORT_AGENT_ID }}",
|
|
189
|
+
"context": {
|
|
190
|
+
"repo": "${{ github.repository }}",
|
|
191
|
+
"base": "${{ github.event.pull_request.base.ref }}",
|
|
192
|
+
"head": "${{ github.event.pull_request.head.ref }}",
|
|
193
|
+
"files_changed": ${{ toJson(github.event.pull_request.changed_files) }},
|
|
194
|
+
"author": "${{ github.event.pull_request.user.login }}"
|
|
195
|
+
}
|
|
196
|
+
}'
|
|
197
|
+
env:
|
|
198
|
+
APORT_AGENT_ID: ${{ secrets.APORT_AGENT_ID }}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## 🔧 Creating Custom Policy Packs
|
|
202
|
+
|
|
203
|
+
### 1. Use the Template
|
|
204
|
+
Copy `policy-template.json` and replace placeholders:
|
|
205
|
+
```bash
|
|
206
|
+
cp policy-template.json my-custom-policy.v1.json
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### 2. Define Context Schema
|
|
210
|
+
Update `required_context` with your specific fields:
|
|
211
|
+
```json
|
|
212
|
+
{
|
|
213
|
+
"type": "object",
|
|
214
|
+
"required": ["amount", "currency", "merchant_id"],
|
|
215
|
+
"properties": {
|
|
216
|
+
"amount": {
|
|
217
|
+
"type": "number",
|
|
218
|
+
"minimum": 0.01,
|
|
219
|
+
"description": "Transaction amount"
|
|
220
|
+
},
|
|
221
|
+
"currency": {
|
|
222
|
+
"type": "string",
|
|
223
|
+
"enum": ["USD", "EUR", "GBP"],
|
|
224
|
+
"description": "Transaction currency"
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### 3. Add Evaluation Rules
|
|
231
|
+
Define OAP-compliant evaluation rules:
|
|
232
|
+
```json
|
|
233
|
+
{
|
|
234
|
+
"evaluation_rules": [
|
|
235
|
+
{
|
|
236
|
+
"name": "amount_within_limits",
|
|
237
|
+
"condition": "context.amount <= limits.my_capability.max_amount",
|
|
238
|
+
"deny_code": "oap.limit_exceeded",
|
|
239
|
+
"description": "Transaction amount exceeds allowed limit"
|
|
240
|
+
}
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### 4. Configure Enforcement
|
|
246
|
+
Set up enforcement rules in the `enforcement` object:
|
|
247
|
+
```json
|
|
248
|
+
{
|
|
249
|
+
"enforcement": {
|
|
250
|
+
"assurance_required": "limits.my_capability.require_assurance_at_least",
|
|
251
|
+
"idempotency_required": true,
|
|
252
|
+
"custom_rule": "limits.my_capability.custom_limit"
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## 🧪 Testing Policy Packs
|
|
258
|
+
|
|
259
|
+
Each policy pack includes comprehensive test suites:
|
|
260
|
+
|
|
261
|
+
### Test Structure
|
|
262
|
+
```
|
|
263
|
+
policy-name.v1/
|
|
264
|
+
├── policy.json # Policy definition
|
|
265
|
+
├── README.md # Documentation
|
|
266
|
+
├── express.example.js # Express.js example
|
|
267
|
+
├── fastapi.example.py # FastAPI example
|
|
268
|
+
├── minimal-example.js # Minimal implementation
|
|
269
|
+
└── tests/
|
|
270
|
+
├── passport.template.json # Template passport
|
|
271
|
+
├── passport.instance.json # Instance passport
|
|
272
|
+
├── contexts.jsonl # Test contexts
|
|
273
|
+
├── expected.jsonl # Expected decisions
|
|
274
|
+
├── policy-name.test.js # JavaScript tests
|
|
275
|
+
└── test_policy_name.py # Python tests
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Running Tests
|
|
279
|
+
```bash
|
|
280
|
+
# JavaScript tests
|
|
281
|
+
npm test
|
|
282
|
+
|
|
283
|
+
# Python tests
|
|
284
|
+
python -m pytest
|
|
285
|
+
|
|
286
|
+
# Conformance testing
|
|
287
|
+
npx @aporthq/oap-conformance policy-name.v1/
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## 📊 OAP Compliance Standards
|
|
291
|
+
|
|
292
|
+
### Error Codes
|
|
293
|
+
Always use OAP standard error codes:
|
|
294
|
+
- `oap.passport_suspended` - Agent is suspended
|
|
295
|
+
- `oap.assurance_insufficient` - Assurance level too low
|
|
296
|
+
- `oap.unknown_capability` - Missing required capability
|
|
297
|
+
- `oap.limit_exceeded` - Exceeded limits
|
|
298
|
+
- `oap.currency_unsupported` - Unsupported currency
|
|
299
|
+
- `oap.region_blocked` - Region not allowed
|
|
300
|
+
- `oap.idempotency_conflict` - Duplicate idempotency key
|
|
301
|
+
|
|
302
|
+
### Limits Structure
|
|
303
|
+
Use nested limits under capability names:
|
|
304
|
+
```json
|
|
305
|
+
{
|
|
306
|
+
"limits": {
|
|
307
|
+
"payments.charge": {
|
|
308
|
+
"currency_limits": {
|
|
309
|
+
"USD": { "max_per_tx": 10000 },
|
|
310
|
+
"EUR": { "max_per_tx": 8500 }
|
|
311
|
+
},
|
|
312
|
+
"require_assurance_at_least": "L2",
|
|
313
|
+
"idempotency_required": true,
|
|
314
|
+
"allowed_merchant_ids": ["merchant_123", "merchant_456"]
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Assurance Levels
|
|
321
|
+
- **L1** - Basic verification (email, domain)
|
|
322
|
+
- **L2** - Enhanced verification (GitHub, social proof)
|
|
323
|
+
- **L3** - High assurance (KYC, legal verification)
|
|
324
|
+
|
|
325
|
+
## 🔄 Migration Guide
|
|
326
|
+
|
|
327
|
+
### From Legacy Policies
|
|
328
|
+
1. Add missing OAP fields (`status`, `cache`, `evaluation_rules`)
|
|
329
|
+
2. Update error codes to OAP standard (`oap.*`)
|
|
330
|
+
3. Add JSON Schema validation (`required_context`)
|
|
331
|
+
4. Update limits structure to nested format
|
|
332
|
+
5. Add comprehensive evaluation rules
|
|
333
|
+
|
|
334
|
+
### Version Updates
|
|
335
|
+
- Update `version` field
|
|
336
|
+
- Update `updated_at` timestamp
|
|
337
|
+
- Document changes in policy description
|
|
338
|
+
- Maintain backward compatibility where possible
|
|
339
|
+
|
|
340
|
+
## 📚 Resources
|
|
341
|
+
|
|
342
|
+
- **[OAP v1.0 Specification](https://github.com/aporthq/aport-spec)** - Complete normative specification
|
|
343
|
+
- **[Policy Verification API](../functions/api/verify/policy/)** - Real-time policy evaluation
|
|
344
|
+
- **[Middleware Examples](../middleware/)** - Framework integrations
|
|
345
|
+
- **[SDK Documentation](../sdk/)** - Client libraries
|
|
346
|
+
- **[Conformance Testing](https://github.com/aporthq/aport-spec/tree/main/conformance)** - OAP compliance validation
|
|
347
|
+
|
|
348
|
+
## 🤝 Contributing
|
|
349
|
+
|
|
350
|
+
We welcome contributions to policy packs! Whether it's:
|
|
351
|
+
|
|
352
|
+
- 🐛 **Bug fixes** in existing policies
|
|
353
|
+
- ✨ **New policy packs** for additional use cases
|
|
354
|
+
- 📚 **Documentation** improvements
|
|
355
|
+
- 🧪 **Test coverage** enhancements
|
|
356
|
+
|
|
357
|
+
Check out our [Contributing Guide](CONTRIBUTING.md) to get started.
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
**🛡️ Secure your AI agents. Trust but verify.**
|
|
362
|
+
|
|
363
|
+
**Last Updated**: 2026-02-15 18:32:09 UTC
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
# Agent Session Creation Policy v1
|
|
2
|
+
|
|
3
|
+
**Policy ID:** `agent.session.create.v1`
|
|
4
|
+
**Status:** Active
|
|
5
|
+
**Min Assurance:** L1
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
The Agent Session Creation Policy provides pre-action governance for AI agent session creation. This policy enforces session limits, duration restrictions, concurrent session controls, and resource allocation to ensure secure and efficient multi-session agent deployments.
|
|
10
|
+
|
|
11
|
+
## Use Cases
|
|
12
|
+
|
|
13
|
+
- **Multi-User AI Platforms**: Managing sessions across multiple users
|
|
14
|
+
- **Development Agents**: Creating sessions for different projects/workspaces
|
|
15
|
+
- **Batch Processing**: Creating ephemeral sessions for background tasks
|
|
16
|
+
- **Interactive Chat**: Managing conversational agent sessions
|
|
17
|
+
- **Scheduled Tasks**: Creating sessions for cron-like operations
|
|
18
|
+
|
|
19
|
+
## Required Capabilities
|
|
20
|
+
|
|
21
|
+
- `agent.session.create`
|
|
22
|
+
|
|
23
|
+
## Required Limits
|
|
24
|
+
|
|
25
|
+
- `max_sessions_per_user` (integer): Maximum sessions per user
|
|
26
|
+
- `max_session_duration` (integer): Maximum session duration in seconds
|
|
27
|
+
|
|
28
|
+
## Optional Limits
|
|
29
|
+
|
|
30
|
+
- `max_concurrent_sessions` (integer): Maximum concurrent active sessions
|
|
31
|
+
- `allowed_session_types` (array): Allowed session types
|
|
32
|
+
- `max_sessions_per_day` (integer): Maximum sessions created per day
|
|
33
|
+
- `resource_quota` (object): Resource limits (memory, CPU, storage)
|
|
34
|
+
- `default_session_duration` (integer): Default duration if not specified
|
|
35
|
+
- `require_session_names` (boolean): Require human-readable names
|
|
36
|
+
|
|
37
|
+
## Context Schema
|
|
38
|
+
|
|
39
|
+
### Required Fields
|
|
40
|
+
|
|
41
|
+
- `user_id` (string): User identifier for session owner
|
|
42
|
+
- `session_type` (enum): Type of session (interactive, batch, webhook, scheduled, ephemeral)
|
|
43
|
+
|
|
44
|
+
### Optional Fields
|
|
45
|
+
|
|
46
|
+
- `session_name` (string): Human-readable session name
|
|
47
|
+
- `requested_duration` (integer): Requested session duration in seconds
|
|
48
|
+
- `resources` (object): Resource requirements (memory_mb, cpu_millicores, storage_gb)
|
|
49
|
+
- `metadata` (object): Custom metadata
|
|
50
|
+
- `parent_session_id` (string): Parent session for nested sessions
|
|
51
|
+
- `tags` (array): Tags for organization
|
|
52
|
+
- `mcp_servers`, `mcp_tools`, `mcp_session`: MCP integration fields
|
|
53
|
+
|
|
54
|
+
## Evaluation Rules
|
|
55
|
+
|
|
56
|
+
1. **passport_status_active**: Passport must be active
|
|
57
|
+
2. **session_capability**: Agent must have `agent.session.create` capability
|
|
58
|
+
3. **session_limit_per_user**: User must not exceed max sessions
|
|
59
|
+
4. **concurrent_session_limit**: Agent must not exceed concurrent sessions
|
|
60
|
+
5. **session_duration_limit**: Duration must not exceed maximum
|
|
61
|
+
6. **session_type_allowed**: Session type must be allowed
|
|
62
|
+
7. **resource_quota**: Requested resources must be within quota
|
|
63
|
+
8. **daily_session_limit**: Daily session creations must not exceed limit
|
|
64
|
+
|
|
65
|
+
## Example Passport Limits
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"limits": {
|
|
70
|
+
"agent.session.create": {
|
|
71
|
+
"max_sessions_per_user": 10,
|
|
72
|
+
"max_concurrent_sessions": 50,
|
|
73
|
+
"max_session_duration": 3600,
|
|
74
|
+
"max_sessions_per_day": 100,
|
|
75
|
+
"allowed_session_types": [
|
|
76
|
+
"interactive",
|
|
77
|
+
"batch",
|
|
78
|
+
"scheduled",
|
|
79
|
+
"ephemeral"
|
|
80
|
+
],
|
|
81
|
+
"resource_quota": {
|
|
82
|
+
"memory_mb": 4096,
|
|
83
|
+
"cpu_millicores": 2000,
|
|
84
|
+
"storage_gb": 10
|
|
85
|
+
},
|
|
86
|
+
"default_session_duration": 1800,
|
|
87
|
+
"require_session_names": false
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Example Request Context
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"user_id": "user_abc123",
|
|
98
|
+
"session_type": "interactive",
|
|
99
|
+
"session_name": "Code Review Session",
|
|
100
|
+
"requested_duration": 3600,
|
|
101
|
+
"resources": {
|
|
102
|
+
"memory_mb": 2048,
|
|
103
|
+
"cpu_millicores": 1000,
|
|
104
|
+
"storage_gb": 5
|
|
105
|
+
},
|
|
106
|
+
"metadata": {
|
|
107
|
+
"project": "myproject",
|
|
108
|
+
"environment": "development"
|
|
109
|
+
},
|
|
110
|
+
"tags": ["code-review", "pr-123"]
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Example Decision (Allow)
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"decision_id": "dec_sess001",
|
|
119
|
+
"policy_id": "agent.session.create.v1",
|
|
120
|
+
"passport_id": "pass_abc123",
|
|
121
|
+
"owner_id": "org_12345",
|
|
122
|
+
"assurance_level": "L1",
|
|
123
|
+
"allow": true,
|
|
124
|
+
"reasons": [{
|
|
125
|
+
"code": "oap.allowed",
|
|
126
|
+
"message": "All policy checks passed"
|
|
127
|
+
}],
|
|
128
|
+
"issued_at": "2026-02-14T22:00:00Z",
|
|
129
|
+
"expires_at": "2026-02-14T22:01:00Z",
|
|
130
|
+
"passport_digest": "sha256:...",
|
|
131
|
+
"signature": "ed25519:...",
|
|
132
|
+
"kid": "oap:registry:key-2026-02"
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Example Decision (Deny - Session Limit)
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"decision_id": "dec_sess002",
|
|
141
|
+
"policy_id": "agent.session.create.v1",
|
|
142
|
+
"passport_id": "pass_abc123",
|
|
143
|
+
"owner_id": "org_12345",
|
|
144
|
+
"assurance_level": "L1",
|
|
145
|
+
"allow": false,
|
|
146
|
+
"reasons": [{
|
|
147
|
+
"code": "oap.session_limit_exceeded",
|
|
148
|
+
"message": "User has reached maximum of 10 sessions"
|
|
149
|
+
}],
|
|
150
|
+
"issued_at": "2026-02-14T22:00:00Z",
|
|
151
|
+
"expires_at": "2026-02-14T22:01:00Z",
|
|
152
|
+
"passport_digest": "sha256:...",
|
|
153
|
+
"signature": "ed25519:...",
|
|
154
|
+
"kid": "oap:registry:key-2026-02"
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Security Best Practices
|
|
159
|
+
|
|
160
|
+
1. **Session Limits**: Prevent resource exhaustion with per-user limits
|
|
161
|
+
2. **Duration Caps**: Set maximum durations to prevent zombie sessions
|
|
162
|
+
3. **Concurrent Controls**: Limit active sessions to manage system load
|
|
163
|
+
4. **Resource Quotas**: Enforce memory/CPU/storage limits
|
|
164
|
+
5. **Session Tracking**: Log all session creations for auditing
|
|
165
|
+
6. **Session Types**: Use types to apply different policies
|
|
166
|
+
7. **Auto-Expiration**: Implement automatic session cleanup
|
|
167
|
+
8. **Progressive Limits**: Start strict and relax for trusted users
|
|
168
|
+
9. **Status Webhooks**: Subscribe for instant revocation
|
|
169
|
+
10. **Session Tagging**: Enable organization and cost allocation
|
|
170
|
+
|
|
171
|
+
## Session Types
|
|
172
|
+
|
|
173
|
+
### Interactive
|
|
174
|
+
- User-facing chat or CLI sessions
|
|
175
|
+
- Typically shorter duration (minutes to hours)
|
|
176
|
+
- Requires real-time responsiveness
|
|
177
|
+
|
|
178
|
+
### Batch
|
|
179
|
+
- Background processing tasks
|
|
180
|
+
- Can be longer duration (hours)
|
|
181
|
+
- Lower priority for resources
|
|
182
|
+
|
|
183
|
+
### Webhook
|
|
184
|
+
- Triggered by external events
|
|
185
|
+
- Short-lived (seconds to minutes)
|
|
186
|
+
- Event-driven lifecycle
|
|
187
|
+
|
|
188
|
+
### Scheduled
|
|
189
|
+
- Cron-like scheduled tasks
|
|
190
|
+
- Predictable execution patterns
|
|
191
|
+
- Can be recurring
|
|
192
|
+
|
|
193
|
+
### Ephemeral
|
|
194
|
+
- Temporary, disposable sessions
|
|
195
|
+
- Very short duration (seconds)
|
|
196
|
+
- Minimal resource allocation
|
|
197
|
+
|
|
198
|
+
## Error Codes
|
|
199
|
+
|
|
200
|
+
- `oap.passport_suspended`: Passport is not active
|
|
201
|
+
- `oap.unknown_capability`: Missing agent.session.create capability
|
|
202
|
+
- `oap.session_limit_exceeded`: User exceeded max sessions
|
|
203
|
+
- `oap.concurrent_limit_exceeded`: Too many concurrent sessions
|
|
204
|
+
- `oap.duration_limit_exceeded`: Requested duration too long
|
|
205
|
+
- `oap.session_type_not_allowed`: Session type not allowed
|
|
206
|
+
- `oap.resource_quota_exceeded`: Requested resources exceed quota
|
|
207
|
+
- `oap.daily_limit_exceeded`: Daily session creation limit exceeded
|
|
208
|
+
|
|
209
|
+
## Integration Examples
|
|
210
|
+
|
|
211
|
+
### TypeScript (Session Manager)
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
import axios from 'axios';
|
|
215
|
+
|
|
216
|
+
interface SessionRequest {
|
|
217
|
+
userId: string;
|
|
218
|
+
sessionType: 'interactive' | 'batch' | 'webhook' | 'scheduled' | 'ephemeral';
|
|
219
|
+
sessionName?: string;
|
|
220
|
+
requestedDuration?: number;
|
|
221
|
+
resources?: {
|
|
222
|
+
memory_mb?: number;
|
|
223
|
+
cpu_millicores?: number;
|
|
224
|
+
storage_gb?: number;
|
|
225
|
+
};
|
|
226
|
+
metadata?: Record<string, any>;
|
|
227
|
+
tags?: string[];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async function createSession(
|
|
231
|
+
passport: Passport,
|
|
232
|
+
request: SessionRequest
|
|
233
|
+
): Promise<Session> {
|
|
234
|
+
const context = {
|
|
235
|
+
user_id: request.userId,
|
|
236
|
+
session_type: request.sessionType,
|
|
237
|
+
session_name: request.sessionName,
|
|
238
|
+
requested_duration: request.requestedDuration || 1800,
|
|
239
|
+
resources: request.resources,
|
|
240
|
+
metadata: request.metadata,
|
|
241
|
+
tags: request.tags
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// Check policy
|
|
245
|
+
const decision = await axios.post('https://api.aport.io/v1/decide', {
|
|
246
|
+
passport_id: passport.passport_id,
|
|
247
|
+
policy_id: 'agent.session.create.v1',
|
|
248
|
+
context
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
if (!decision.data.allow) {
|
|
252
|
+
throw new Error(`Session creation blocked: ${decision.data.reasons[0].message}`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Create session
|
|
256
|
+
const session = await createSessionInDatabase(context);
|
|
257
|
+
|
|
258
|
+
// Schedule auto-cleanup
|
|
259
|
+
scheduleSessionCleanup(session.id, context.requested_duration);
|
|
260
|
+
|
|
261
|
+
return session;
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Python (FastAPI)
|
|
266
|
+
|
|
267
|
+
```python
|
|
268
|
+
from datetime import datetime, timedelta
|
|
269
|
+
import httpx
|
|
270
|
+
|
|
271
|
+
async def create_session(
|
|
272
|
+
passport: dict,
|
|
273
|
+
user_id: str,
|
|
274
|
+
session_type: str,
|
|
275
|
+
session_name: str | None = None,
|
|
276
|
+
requested_duration: int = 1800,
|
|
277
|
+
resources: dict | None = None,
|
|
278
|
+
metadata: dict | None = None,
|
|
279
|
+
tags: list[str] | None = None
|
|
280
|
+
) -> dict:
|
|
281
|
+
context = {
|
|
282
|
+
"user_id": user_id,
|
|
283
|
+
"session_type": session_type,
|
|
284
|
+
"session_name": session_name,
|
|
285
|
+
"requested_duration": requested_duration,
|
|
286
|
+
"resources": resources or {},
|
|
287
|
+
"metadata": metadata or {},
|
|
288
|
+
"tags": tags or []
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
# Check policy
|
|
292
|
+
async with httpx.AsyncClient() as client:
|
|
293
|
+
response = await client.post(
|
|
294
|
+
"https://api.aport.io/v1/decide",
|
|
295
|
+
json={
|
|
296
|
+
"passport_id": passport["passport_id"],
|
|
297
|
+
"policy_id": "agent.session.create.v1",
|
|
298
|
+
"context": context
|
|
299
|
+
}
|
|
300
|
+
)
|
|
301
|
+
decision = response.json()
|
|
302
|
+
|
|
303
|
+
if not decision["allow"]:
|
|
304
|
+
raise PermissionError(f"Session creation blocked: {decision['reasons'][0]['message']}")
|
|
305
|
+
|
|
306
|
+
# Create session
|
|
307
|
+
session = await create_session_in_database(context)
|
|
308
|
+
|
|
309
|
+
# Schedule auto-cleanup
|
|
310
|
+
expires_at = datetime.utcnow() + timedelta(seconds=requested_duration)
|
|
311
|
+
await schedule_session_cleanup(session["id"], expires_at)
|
|
312
|
+
|
|
313
|
+
return session
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## Resource Management
|
|
317
|
+
|
|
318
|
+
Sessions should track and enforce resource usage:
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
interface SessionResources {
|
|
322
|
+
memory_mb: number; // RAM allocation
|
|
323
|
+
cpu_millicores: number; // CPU allocation (1000 = 1 core)
|
|
324
|
+
storage_gb: number; // Disk allocation
|
|
325
|
+
network_mbps: number; // Network bandwidth
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Calculate resource costs
|
|
329
|
+
function calculateResourceCost(resources: SessionResources, duration_hours: number): number {
|
|
330
|
+
const memory_cost = (resources.memory_mb / 1024) * 0.01 * duration_hours;
|
|
331
|
+
const cpu_cost = (resources.cpu_millicores / 1000) * 0.05 * duration_hours;
|
|
332
|
+
const storage_cost = resources.storage_gb * 0.001 * duration_hours;
|
|
333
|
+
|
|
334
|
+
return memory_cost + cpu_cost + storage_cost;
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## Version History
|
|
339
|
+
|
|
340
|
+
- **v1.0.0** (2026-02-14): Initial release
|
|
341
|
+
|
|
342
|
+
## References
|
|
343
|
+
|
|
344
|
+
- [OAP Specification](https://github.com/aporthq/aport-spec)
|
|
345
|
+
- [Session Management Best Practices](https://docs.aport.io/sessions)
|