| 518 | } |
| 519 | |
| 520 | func NewAPI(store *identity.Store, sender *outbound.Sender, smtpRelay *outbound.SMTPRelay, userAuth *auth.UserAuth, usage usage.UsageTracker, smtpDomain, fromDomain, sharedDomain, publicURL string, production bool) *API { |
| 521 | return &API{ |
| 522 | store: store, |
| 523 | sender: sender, |
| 524 | screen: piguard.NewEngine(piguard.EngineConfig{}, piguard.NewHeuristicsDetector()), |
| 525 | smtpRelay: smtpRelay, |
| 526 | userAuth: userAuth, |
| 527 | usage: usage, |
| 528 | smtpDomain: smtpDomain, |
| 529 | fromDomain: fromDomain, |
| 530 | sharedDomain: sharedDomain, |
| 531 | publicURL: publicURL, |
| 532 | // Default the API/issuer URL to the web URL; SetAPIURL overrides it |
| 533 | // for split web/API-host deployments. |
| 534 | apiURL: publicURL, |
| 535 | production: production, |
| 536 | sendLimit: ratelimit.New(1*time.Minute, 60), // 60 sends per agent per minute |
| 537 | regLimit: ratelimit.New(1*time.Hour, 200), // 200 registrations per IP per hour |
| 538 | pollLimit: ratelimit.New(1*time.Minute, 60), // 60 poll requests per user per minute |
| 539 | feedbackLimit: ratelimit.New(1*time.Hour, 10), // 10 feedback submissions per IP per hour |
| 540 | dcrLimit: ratelimit.New(1*time.Hour, 10), // 10 OAuth client registrations per IP per hour |
| 541 | downloadLimit: ratelimit.New(1*time.Minute, 120), // 120 attachment downloads per IP per minute |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | // SetAPIURL overrides the API/issuer base URL (default: publicURL). Set it |
| 546 | // when the programmatic API + MCP are served on a different host than the web |