# Cambium

Every registered cambium instance operation, with source-derived inputs, outputs, access policy, and errors.

Source: https://docs.minds.sh/docs/api/instance/cambium



This reference covers **2 HTTP operations** registered by the Akasha daemon. Call these paths on your instance base URL. See [authentication](/docs/api/instance/authentication), [errors](/docs/api/instance/errors), and [coverage](/docs/api/instance/coverage) before integrating.

| Method | Path                      | Operation                                                 |
| ------ | ------------------------- | --------------------------------------------------------- |
| `POST` | `/v1/cambium/projections` | [Cambium projection ingest](#post-v1-cambium-projections) |
| `POST` | `/v1/advice/tools:rank`   | [Cambium tool advisor rank](#post-v1-advice-tools-rank)   |

<a id="post-v1-cambium-projections" />

## POST `/v1/cambium/projections` [#post-v1cambiumprojections]

Cambium projection ingest

| Availability         | Source contract                                                  |
| -------------------- | ---------------------------------------------------------------- |
| Registration         | `always registered`                                              |
| Runtime service      | No prefix-level service check; handler dependencies still apply. |
| Handler dependencies | See handler source and return expressions.                       |

**Access:** Global auth bypass; this handler performs Cambium-specific caller authentication.

### Request [#request]

**Json** — `CambiumProjectionEnvelope`

| Field               | Rust type        | Required on input         | Notes                                        |
| ------------------- | ---------------- | ------------------------- | -------------------------------------------- |
| `projectionId`      | `String`         | Yes                       |                                              |
| `target`            | `String`         | Yes                       |                                              |
| `sinkId`            | `String`         | Yes                       |                                              |
| `projectionClass`   | `String`         | Yes                       |                                              |
| `sourceEventId`     | `String`         | Yes                       |                                              |
| `streamId`          | `String`         | Yes                       |                                              |
| `sequence`          | `u64`            | Yes                       |                                              |
| `globalSequence`    | `u64`            | Yes                       |                                              |
| `traceId`           | `Option<String>` | No; optional or defaulted |                                              |
| `spanId`            | `Option<String>` | No; optional or defaulted |                                              |
| `scope`             | `Value`          | Yes                       |                                              |
| `lineage`           | `Value`          | Yes                       |                                              |
| `dataClass`         | `String`         | Yes                       |                                              |
| `redactionProfile`  | `String`         | Yes                       |                                              |
| `sourcePayloadHash` | `String`         | Yes                       |                                              |
| `evidenceRefs`      | `Vec<String>`    | No; optional or defaulted | Serde: `default`                             |
| `activitySummary`   | `Option<String>` | No; optional or defaulted |                                              |
| `toolId`            | `Option<String>` | No; optional or defaulted |                                              |
| `toolScoreSample`   | `Option<Value>`  | No; optional or defaulted | Serde: `rename = "toolScoreSample", default` |
| `derived`           | `bool`           | Yes                       |                                              |
| `createdAt`         | `String`         | Yes                       |                                              |

```rust
struct CambiumProjectionEnvelope {
    projection_id: String,
    target: String,
    sink_id: String,
    projection_class: String,
    source_event_id: String,
    stream_id: String,
    sequence: u64,
    global_sequence: u64,
    trace_id: Option<String>,
    span_id: Option<String>,
    scope: Value,
    lineage: Value,
    data_class: String,
    redaction_profile: String,
    source_payload_hash: String,
    #[serde(default)]
    evidence_refs: Vec<String>,
    activity_summary: Option<String>,
    tool_id: Option<String>,
    #[serde(rename = "toolScoreSample", default)]
    _tool_score_sample: Option<Value>,
    derived: bool,
    created_at: String,
}
```

### Response [#response]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
json!({
            "accepted": true,
            "projectionId": summary.projection_id,
            "projectionClass": summary.projection_class,
            "sourceEventId": summary.source_event_id,
            "akashaNamespace": summary.akasha_namespace
        })
```

### Errors and validation [#errors-and-validation]

Directly referenced error variants: none in the handler body. Middleware and delegated services can return additional errors described in the shared error reference.

Explicit status constants: `ACCEPTED`.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn cambium_projection_ingest(
        State(state): State<AppState>,
        headers: HeaderMap,
        Json(envelope): Json<CambiumProjectionEnvelope>,
    ) -> Result<impl IntoResponse, DaemonError> {
        authorize_cambium(&headers)?;
        let summary = state.cambium_projection_store().push(envelope).await?;
        Ok((
            axum::http::StatusCode::ACCEPTED,
            Json(json!({
                "accepted": true,
                "projectionId": summary.projection_id,
                "projectionClass": summary.projection_class,
                "sourceEventId": summary.source_event_id,
                "akashaNamespace": summary.akasha_namespace
            })),
        ))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/cambium.rs:259`. Registration: `akasha-daemon/src/main.rs:4362`.

<a id="post-v1-advice-tools-rank" />

## POST `/v1/advice/tools:rank` [#post-v1advicetoolsrank]

Cambium tool advisor rank

| Availability         | Source contract                                                  |
| -------------------- | ---------------------------------------------------------------- |
| Registration         | `always registered`                                              |
| Runtime service      | No prefix-level service check; handler dependencies still apply. |
| Handler dependencies | See handler source and return expressions.                       |

**Access:** Global auth bypass; this handler performs Cambium-specific caller authentication.

### Request [#request-1]

**Json** — `ToolAdvisorRankRequest`

| Field             | Rust type        | Required on input         | Notes            |
| ----------------- | ---------------- | ------------------------- | ---------------- |
| `taskClass`       | `Option<String>` | No; optional or defaulted |                  |
| `taskIntent`      | `Option<String>` | No; optional or defaulted |                  |
| `scope`           | `Value`          | Yes                       |                  |
| `sourceEventId`   | `String`         | Yes                       |                  |
| `runId`           | `Option<String>` | No; optional or defaulted |                  |
| `candidates`      | `Vec<String>`    | No; optional or defaulted | Serde: `default` |
| `policySourceRef` | `Option<String>` | No; optional or defaulted |                  |

```rust
struct ToolAdvisorRankRequest {
    task_class: Option<String>,
    task_intent: Option<String>,
    scope: Value,
    source_event_id: String,
    run_id: Option<String>,
    #[serde(default)]
    candidates: Vec<String>,
    policy_source_ref: Option<String>,
}
```

### Response [#response-1]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
json!({
        "recommendationId": format!("akasha_tool_advisor_{}", sanitize_identifier(&req.source_event_id)),
        "taskClass": req.task_class,
        "taskIntent": req.task_intent,
        "sourceEventId": req.source_event_id,
        "runId": req.run_id,
        "scope": req.scope,
        "rankedTools": ranked_tools,
        "evidenceRefs": event_projections
            .iter()
            .flat_map(|projection| projection.evidence_refs.clone())
            .chain(std::iter::once(req.source_event_id))
            .collect::<Vec<_>>(),
        "policy": {
            "sourceRef": req.policy_source_ref.unwrap_or_else(|| "akasha://policy/default".to_string()),
            "deniedTools": denied_tools
        }
    })
```

### Errors and validation [#errors-and-validation-1]

Directly referenced error variants: `InvalidRequest`. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn cambium_tool_advisor_rank(
        State(state): State<AppState>,
        headers: HeaderMap,
        Json(req): Json<ToolAdvisorRankRequest>,
    ) -> Result<impl IntoResponse, DaemonError> {
        authorize_cambium(&headers)?;
        if req.source_event_id.trim().is_empty() {
            return Err(DaemonError::InvalidRequest(
                "sourceEventId is required for ToolAdvisor ranking".into(),
            ));
        }

        let store = state.cambium_projection_store();
        let event_projections = store.projections_for_event(&req.source_event_id).await;
        let denied_projections = store.denied_tools_for_run(req.run_id.as_deref()).await;
        let denied_tool_ids: Vec<String> = denied_projections
            .iter()
            .filter_map(|entry| entry.tool_id.clone())
            .collect();

        let candidates = if req.candidates.is_empty() {
            inferred_candidates(&event_projections)
        } else {
            req.candidates.clone()
        };
        let mut ranked_tools = Vec::new();
        for candidate in candidates {
            if denied_tool_ids.iter().any(|tool| tool == &candidate) {
                continue;
            }
            let mut evidence_refs = vec![req.source_event_id.clone()];
            for projection in event_projections
                .iter()
                .filter(|projection| projection.tool_id.as_deref() == Some(candidate.as_str()))
            {
                evidence_refs.push(projection.projection_id.clone());
                evidence_refs.extend(projection.evidence_refs.clone());
            }
            evidence_refs.sort();
            evidence_refs.dedup();
            ranked_tools.push(json!({
                "toolId": candidate,
                "score": 1.0_f64 / (ranked_tools.len() as f64 + 1.0),
                "evidenceRefs": evidence_refs,
                "rationale": "ranked from sanitized Cambium Akasha learning projections"
            }));
        }

        if ranked_tools.is_empty() {
            return Err(DaemonError::InvalidRequest(
                "no rankable tools remain after policy filtering".into(),
            ));
        }

        for (index, tool) in ranked_tools.iter_mut().enumerate() {
            if let Some(object) = tool.as_object_mut() {
                object.insert("rank".to_string(), json!(index + 1));
            }
        }

        let denied_tools: Vec<Value> = denied_projections
            .iter()
            .filter_map(|projection| {
                projection.tool_id.as_ref().map(|tool_id| {
                    json!({
                        "toolId": tool_id,
                        "reason": "learning_quarantine_candidate",
                        "evidenceRefs": projection.evidence_refs,
                        "sourceEventId": projection.source_event_id
                    })
                })
            })
            .collect();

        Ok(Json(json!({
            "recommendationId": format!("akasha_tool_advisor_{}", sanitize_identifier(&req.source_event_id)),
            "taskClass": req.task_class,
            "taskIntent": req.task_intent,
            "sourceEventId": req.source_event_id,
            "runId": req.run_id,
            "scope": req.scope,
            "rankedTools": ranked_tools,
            "evidenceRefs": event_projections
                .iter()
                .flat_map(|projection| projection.evidence_refs.clone())
                .chain(std::iter::once(req.source_event_id))
                .collect::<Vec<_>>(),
            "policy": {
                "sourceRef": req.policy_source_ref.unwrap_or_else(|| "akasha://policy/default".to_string()),
                "deniedTools": denied_tools
            }
        })))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/cambium.rs:278`. Registration: `akasha-daemon/src/main.rs:4366`.
