drupal-mods/commerce-agent-detector
Composer 安装命令:
composer require drupal-mods/commerce-agent-detector
包简介
Detects AI procurement/shopping agents and switches the commerce experience to machine-optimized mode.
README 文档
README
A Drupal module that automatically detects AI procurement/shopping agents and serves machine-optimized JSON commerce endpoints — while keeping the human experience 100% unchanged.
Features
Core
- Automatic agent detection — identifies ChatGPT, Claude, Claude Managed Agents, Gemini, Perplexity, Copilot, and custom agents via tokens, headers, user-agent strings, and optional heuristics
- JSON commerce API — search, product detail, cart, and checkout endpoints with Schema.org structured data
- Token management — SHA-256 hashed, customer-bound API tokens with scopes, expiration, and usage tracking
- Customer self-service — "Connected Agents" tab on user profiles for generating and revoking personal tokens
- Order ownership — orders placed via managed tokens are automatically assigned to the customer's account
- Rate limiting — configurable per-window limits via Drupal flood control
- Audit logging — every agent interaction logged with dashboard analytics
- Extensible — event-driven architecture for custom agent personas
- Zero impact on humans — normal site routing is completely unaffected
API Features
- Order tracking — order history and detail endpoints for agents to check status, items, and totals on behalf of customers
- Webhook subscriptions — agents can subscribe to store events (order placed, shipped, refunded, etc.) with HMAC-signed payloads and secret rotation
- Bulk cart operations — add, update, remove, or replace multiple cart items in a single request
- Shipping estimates — get shipping rates and available methods for a given address and order before checkout
- MCP server — Model Context Protocol (v2025-11-25) endpoint for LLM tool-use integration with tool annotations and experimental Tasks API for durable commerce operations
- Product comparison — compare multiple products side-by-side with attribute diffs, price comparison, and recommendations
- Budget-aware search — search products within a budget constraint with price-range facets and smart allocation
- Reorder — one-call reorder from a previous order, automatically recreating the cart with the same items
- Natural language query — POST natural language questions ("find me a red laptop under $1000") and get structured product results
- Inventory checks — real-time stock availability for single items or bulk variation lookups
- Agent sessions — persistent session context (preferences, conversation history) across multiple agent requests
- Returns & refunds — check return eligibility, create RMA requests, and track return status via API
.well-known/agent-commerce.json— standardized discovery endpoint for agents to auto-detect store capabilities, endpoints, and protocols
Discovery & Interoperability
- Agent discovery — OpenAPI 3.1 spec, JSON product sitemap, and enhanced llms.txt for automatic API and catalog discovery
- ACP/UCP protocol support — compatible with OpenAI/Stripe Agentic Commerce Protocol and Google Universal Commerce Protocol
- A2A protocol — Google Agent-to-Agent protocol v1.0 with
/.well-known/agent-card.jsonagent card (legacy/.well-known/agent.jsonalias retained), JSON-RPC handler, and multi-agent delegation for orchestrating agents - OAuth Protected Resource Metadata —
/.well-known/oauth-protected-resourceper RFC 9728 for MCP authorization discovery - Claude Managed Agents — automatic detection and MCP integration for Anthropic's managed agent platform
Architecture
Incoming Request
│
▼
AgentDetectionSubscriber (priority 200)
│
├─ 1. Managed tokens (cad_..., SHA-256, customer-bound)
├─ 2. Legacy tokens (config whitelist)
├─ 3. Agent headers (X-Agent-ID, X-ACP-Version, etc.)
├─ 4. User-Agent patterns (ChatGPT, ClaudeBot, etc.)
└─ 5. Heuristics (opt-in behavioral scoring)
│
├── Agent detected → AgentDetectedEvent → Agent API endpoints
└── Not an agent → Normal Drupal routing (unchanged)
Requirements
| Dependency | Version |
|---|---|
| Drupal | 10.3+ or 11 |
| PHP | 8.2+ |
| Drupal Commerce | 2.38+ or 3.x |
| JSON:API module | core (auto-enabled) |
| REST module | core (auto-enabled) |
Optional: Search API, Commerce API, JSON:API Extras
Installation
Via Composer (Packagist)
composer require drupal-mods/commerce-agent-detector
drush en commerce_agent_detector -y
drush cr
From GitLab (alternative)
composer config repositories.commerce_agent_detector vcs https://gitlab.com/drupal-mods/commerce-agent-detector
composer require drupal-mods/commerce-agent-detector:dev-main
drush en commerce_agent_detector -y
drush cr
The commerce_agent_log and commerce_agent_token database tables are
created automatically. Drupal Commerce and its dependencies (Address,
Entity, Profile, etc.) will be pulled in by Composer if not already installed.
Quick Start
- Enable the module (detection is on by default)
- Go to Commerce → Configuration → Agent Detector to review settings
- Create managed tokens at Agent Detector → Tokens for enterprise agents
- Grant customers the
manage own agent tokenspermission for self-service - Agents access your store via
/api/commerce/agent/*endpoints
Documentation
| Guide | Description |
|---|---|
| Token Management | Managed tokens, customer binding, admin/customer UI, migration from legacy tokens |
| API Reference | All endpoints, parameters, request/response examples, error codes |
| Detection | How detection works, priority order, AgentResult, AgentDetectedEvent |
| Configuration | All settings explained, permissions, admin tabs |
| Security | Rate limiting, token auth, audit logging, input validation, fallbacks |
| Extending | Custom agent personas, programmatic API, adding agent-only routes |
| Testing | PHPUnit test suite, simulation script, cURL examples |
API Endpoints
Search & Products
| Method | Path | Description |
|---|---|---|
GET | /api/commerce/agent/search | Search products |
GET | /api/commerce/agent/product/{id} | View product detail |
GET,POST | /api/commerce/agent/products/compare | Compare multiple products |
POST | /api/commerce/agent/budget/search | Budget-constrained search |
GET | /api/commerce/agent/budget/price-ranges | Get price range facets |
POST | /api/commerce/agent/query | Natural language product query |
Cart & Checkout
| Method | Path | Description |
|---|---|---|
GET | /api/commerce/agent/cart | View cart |
POST | /api/commerce/agent/cart/add | Add item to cart |
POST | /api/commerce/agent/cart/bulk-add | Add multiple items |
PATCH | /api/commerce/agent/cart/bulk-update | Update multiple items |
POST | /api/commerce/agent/cart/bulk-remove | Remove multiple items |
POST | /api/commerce/agent/cart/replace | Replace entire cart |
POST | /api/commerce/agent/checkout | Complete checkout |
POST | /api/commerce/agent/reorder | Reorder from previous order |
Orders & Returns
| Method | Path | Description |
|---|---|---|
GET | /api/commerce/agent/orders | Order history |
GET | /api/commerce/agent/order/{id} | Order detail |
GET | /api/commerce/agent/return/eligibility/{order_id} | Check return eligibility |
POST | /api/commerce/agent/return | Create return/RMA |
GET | /api/commerce/agent/return/{return_id} | Get return status |
Shipping & Inventory
| Method | Path | Description |
|---|---|---|
GET,POST | /api/commerce/agent/shipping/estimate | Get shipping rates |
GET | /api/commerce/agent/shipping/methods | List shipping methods |
GET | /api/commerce/agent/inventory/{variation_id} | Check stock |
POST | /api/commerce/agent/inventory/bulk | Bulk stock check |
Webhooks
| Method | Path | Description |
|---|---|---|
GET | /api/commerce/agent/webhooks | List subscriptions |
POST | /api/commerce/agent/webhooks | Subscribe to events |
PATCH | /api/commerce/agent/webhooks/{id} | Update subscription |
DELETE | /api/commerce/agent/webhooks/{id} | Unsubscribe |
POST | /api/commerce/agent/webhooks/{id}/rotate-secret | Rotate webhook secret |
GET | /api/commerce/agent/webhooks/events | List available event types |
Sessions
| Method | Path | Description |
|---|---|---|
POST | /api/commerce/agent/session | Create session |
GET | /api/commerce/agent/session/{id} | Get session |
PATCH | /api/commerce/agent/session/{id} | Update session |
DELETE | /api/commerce/agent/session/{id} | Delete session |
GET | /api/commerce/agent/sessions | List sessions |
Discovery & Protocols
| Method | Path | Description |
|---|---|---|
GET | /api/commerce/agent/openapi.json | OpenAPI 3.1 specification |
GET | /api/commerce/agent/sitemap.json | JSON product sitemap |
GET | /llms.txt | Machine-readable store description |
GET | /.well-known/agent-commerce.json | Agent commerce discovery |
GET | /.well-known/agent-card.json | A2A v1.0 agent card (canonical) |
GET | /.well-known/agent.json | A2A agent card (legacy alias) |
POST | /api/commerce/agent/a2a | A2A JSON-RPC handler |
POST | /api/commerce/agent/mcp | MCP server (v2025-11-25) |
GET | /.well-known/oauth-protected-resource | MCP OAuth metadata (RFC 9728) |
See API Reference for full details.
Agent Dashboard
View traffic analytics at Commerce → Agent Dashboard:
requests, unique agents, orders, revenue, conversion rate, and per-agent
breakdown. Requires the view commerce agent dashboard permission.
How It Works (for Site Owners)
This module watches every request to your Drupal Commerce site. When it detects an AI agent, it serves clean JSON data instead of HTML pages. Human visitors see no change whatsoever — your themes, checkout flow, CAPTCHA, and every other module work exactly as before.
Agents get structured product data, direct cart/checkout APIs, and machine-readable error responses. Orders placed by agents with managed tokens are automatically assigned to the customer's account and appear in their normal order history.
Rate limiting, audit logging, and token authentication ensure your store stays secure. If anything fails, agents get a structured error with a fallback URL to the human version.
License
GPL-2.0-or-later
drupal-mods/commerce-agent-detector 适用场景与选型建议
drupal-mods/commerce-agent-detector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 03 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「drupal」 「headless」 「acp」 「commerce」 「Agent」 「openapi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 drupal-mods/commerce-agent-detector 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 drupal-mods/commerce-agent-detector 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 drupal-mods/commerce-agent-detector 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This extension provides integration with solr to output content from TYPO3 in JSON format.
Provides an add-on purchasable entity.
Instrument headless chrome/chromium instances from php5.6
Drupal integration module for the Kalastatic prototyping and styleguide tool
Provides a base set of configuration and module dependencies for starting new Drupal projects.
Admin Hub for GetCandy. A modern headless e-commerce solution for Laravel PHP framework.
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 36
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2026-03-26