diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md new file mode 100644 index 0000000..c26788d --- /dev/null +++ b/docs/CHANGELOG.md @@ -0,0 +1,220 @@ +--- +icon: material/history +hide: + - toc +--- + +# Changelog + +All notable changes to Nexus are documented here. This project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +--- + +
-The fastest way to get started is with Docker Compose. This will spin up the Broker, Gateway, Postgres, and Redis.
+# Nexus
+
+### Auth infrastructure for autonomous agents.
+
+One authority for every service your agents touch. Nexus orchestrates provider connections, token lifecycle, agent identity, scoped sessions, and on-behalf-of delegation — your agents never write auth code or hold a raw secret.
+
+
+' + text.replace(//g, '>') + ''); + win.document.close(); + } + }); + } + + // Inject widget — prepend to content area + var wrapper = document.createElement('div'); + wrapper.className = 'md-content__button'; + wrapper.style.cssText = 'position:relative;z-index:1;'; + wrapper.appendChild(container); + contentInner.insertBefore(wrapper, contentInner.firstChild); + + // Split-button event handlers + triggerChev.addEventListener('click', function(e) { + e.stopPropagation(); + dropdown.classList.toggle('open'); + }); + + triggerMain.addEventListener('click', function(e) { + e.stopPropagation(); + dropdown.classList.remove('open'); + fetchAndCopy(); + }); + + document.addEventListener('click', function(e) { + if (!container.contains(e.target)) dropdown.classList.remove('open'); + }); +} + +// Run on first load +document.addEventListener('DOMContentLoaded', initLLMWidget); + +// Re-run on every instant navigation (Material for MkDocs SPA mode) +if (typeof document$ !== 'undefined') { + document$.subscribe(initLLMWidget); +} diff --git a/docs/reference/api.md b/docs/reference/api.md index 8420fbf..23f1b34 100644 --- a/docs/reference/api.md +++ b/docs/reference/api.md @@ -1,16 +1,100 @@ +--- +icon: material/code-json +--- + # API Reference -The Nexus Framework uses OpenAPI 3.0 specifications to define its contracts. +Nexus exposes two API surfaces: the **Gateway API**, which agents and applications call, and the **Broker API**, which is internal and used only by the Gateway and administrative tooling. + +The full OpenAPI 3.0 specification is at [`openapi.yaml`](https://github.com/Prescott-Data/nexus-framework/blob/main/openapi.yaml). The v1 surface is frozen — no breaking changes without a major version bump and a deprecation period. + +## Gateway API + +The stable, public-facing surface for all agent integrations. Versioned at `/v1`. + +### Connection endpoints + +| Method | Path | Description | +|---|---|---| +| `POST` | `/v1/request-connection` | Initiate an OAuth handshake or static credential capture | +| `GET` | `/v1/check-connection/{id}` | Poll connection status | +| `GET` | `/v1/token/{id}` | Retrieve credentials for an active connection | +| `POST` | `/v1/refresh/{id}` | Force a token refresh for a connection | +| `GET` | `/v1/capture-schema` | Fetch the credential schema for a static provider | +| `POST` | `/v1/capture-credential` | Submit credentials for a static provider | + +### Agent session endpoints + +| Method | Path | Description | +|---|---|---| +| `POST` | `/v1/agent-sessions` | Request a scoped session for a registered agent | +| `GET` | `/v1/agent-sessions/{id}` | Check session status and metadata | +| `DELETE` | `/v1/agent-sessions/{id}` | Close a session and revoke the token | +| `POST` | `/v1/agent-sessions/obo` | Request an OBO session tied to a user context token | + +### Provider endpoints + +| Method | Path | Description | +|---|---|---| +| `GET` | `/v1/providers` | List all registered providers | +| `GET` | `/v1/providers/metadata` | Grouped metadata for frontend rendering | +| `POST` | `/v1/providers` | Register a new provider | +| `GET` | `/v1/providers/{id}` | Get provider by ID | +| `PATCH` | `/v1/providers/{id}` | Update specific fields of a provider | +| `DELETE` | `/v1/providers/{id}` | Delete a provider | + +### System + +| Method | Path | Description | +|---|---|---| +| `GET` | `/v1/health` | Health check — returns `200 OK` when ready | + +### Authentication + +Connection and token endpoints do not require authentication headers. Access control is enforced by the `connection_id` — only callers holding a valid connection ID can retrieve its credentials. Treat `connection_id` values as session tokens. + +Provider management and agent session endpoints require the `X-API-Key` header. + +### Token response shape + +`GET /v1/token/{id}` returns a structured payload regardless of credential type: + +```json +{ + "strategy": { "type": "oauth2" }, + "credentials": { + "access_token": "eyJ...", + "expires_at": 1715000000 + }, + "scope": "openid email profile", + "expires_at": 1715000000 +} +``` + +The `strategy.type` field tells you how to apply the credentials. See [Authentication Strategies](../concepts/auth-strategies.md) for all strategy types and their credential shapes. + +--- + +## Broker API + +Internal surface. Called by the Gateway and administrative tooling (`nexus-cli`). Do not expose the Broker to agents or untrusted networks. + +The Broker's OpenAPI spec is at [`nexus-broker/openapi.yaml`](https://github.com/Prescott-Data/nexus-framework/blob/main/nexus-broker/openapi.yaml). It evolves between minor versions — fields and endpoints may change. + +### Agent registry endpoints (admin) -## Gateway API (Public) -The Gateway provides the stable, public-facing API for agents and services. +| Method | Path | Description | +|---|---|---| +| `POST` | `/admin/v1/agents` | Register an agent with its allowed scopes | +| `GET` | `/admin/v1/agents` | List all registered agents | +| `GET` | `/admin/v1/agents/{id}` | Get a specific agent | +| `PATCH` | `/admin/v1/agents/{id}` | Update agent allowed scopes | +| `DELETE` | `/admin/v1/agents/{id}` | Deregister an agent | -- **Spec File:** [`openapi.yaml`](../../openapi.yaml) -- **Status:** v1 Frozen. -- **Client SDK:** [`nexus-sdk`](../../nexus-sdk) +### Audit -## Broker API (Internal) -The Broker provides the internal API for provider management and token operations. +| Method | Path | Description | +|---|---|---| +| `GET` | `/audit` | Query audit log events | -- **Spec File:** [`nexus-broker/openapi.yaml`](../../nexus-broker/openapi.yaml) -- **Status:** Internal / Evolving. +All Broker API calls require the `X-API-Key` header. See the [Audit Log](audit-log.md) guide for query parameters and response schema. diff --git a/docs/reference/audit-log.md b/docs/reference/audit-log.md index c6e6574..a489a53 100644 --- a/docs/reference/audit-log.md +++ b/docs/reference/audit-log.md @@ -1,129 +1,89 @@ -# Audit Log Reference - -The Nexus Broker maintains a tamper-evident **audit log** of every control-plane mutation. Every time a provider is created, updated, or deleted — or an OAuth connection is established — a structured record is written to the `audit_events` table. +--- +icon: material/clipboard-text-clock-outline +--- -This provides a queryable history of who changed what and when, which is essential for operating Nexus as critical infrastructure. +# Audit Log ---- +The Nexus Broker maintains a tamper-evident audit log of every control-plane mutation. The log is written to the `audit_events` table in PostgreSQL and is queryable through the Broker's REST API. -## Audited Events - -| Event Type | Trigger | -| :--- | :--- | -| `provider.created` | A new provider profile is registered via `POST /providers` | -| `provider.updated` | A provider's configuration is modified (`PUT` or `PATCH`) | -| `provider.deleted` | A provider is deleted (by ID or by name) | -| `oauth_flow_completed` | An OAuth callback completes successfully and a connection is established | -| `token_exchange_failed` | The authorization code → token exchange failed | -| `token_storage_failed` | Tokens were exchanged but could not be encrypted/stored | -| `token_retrieved` | A downstream service fetched a connection's token via `GET /connections/{id}/token` | -| `token_retrieval_failed` | A token fetch failed (not found, decryption error, inactive connection, etc.) | -| `token_refresh_fatal` | A refresh token was rejected by the provider (4xx), connection moved to `attention` | -| `oauth_error` | The provider returned an error on the OAuth callback (e.g. `access_denied`) | +The audit log records who did what to which resource, and when. It is the primary tool for answering compliance questions ("when was this provider created?"), forensic questions ("why did this agent lose access?"), and operational questions ("which connections were affected by the provider update on the 8th?"). --- -## Query the Audit Log - -``` -GET /audit -``` +## What is logged -Returns recent audit events in descending chronological order. This endpoint is protected by `ApiKeyMiddleware`. +Every event in the audit log carries an event type, structured event data, the caller's IP address, and the User-Agent string. -> **Note:** The Nexus Broker API is unversioned — all routes are mounted at the root (e.g., `/providers`, `/audit`). The `/v1/audit` path referenced elsewhere is aspirational and will apply if/when the Broker adopts a versioned API prefix. +| Event type | When it is written | +|---|---| +| `provider.created` | On every successful `POST /providers` | +| `provider.updated` | On every `PUT` or `PATCH` to a provider | +| `provider.deleted` | On every successful provider deletion | +| `connection.created` | On every successful OAuth callback (token exchange completed) | +| `token.retrieved` | On every successful `GET /connections/{id}/token` | +| `token.exchange_failed` | When the OAuth token exchange fails during a callback | +| `token.storage_failed` | When token encryption or database write fails | +| `token.refresh_fatal` | When a background refresh fails permanently (4xx from provider) | -### Query Parameters +--- -| Parameter | Type | Description | -| :--- | :--- | :--- | -| `event_type` | string | Filter by event type (e.g. `provider.deleted`) | -| `since` | string | RFC3339 timestamp — only return events after this time | -| `limit` | integer | Maximum records to return (default: `50`, max: `1000`) | +## Querying the audit log -### Examples +The audit log is available at `GET /audit` on the Broker. All requests require the `X-API-Key` header. -**Fetch the last 50 audit events:** ```bash curl -s "http://localhost:8080/audit" \ - -H "X-API-Key: