Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 113 additions & 1 deletion apps/elf-api/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ const VIEWER_HTML: &str = include_str!("../static/viewer.html");
admin_core_block_upsert,
admin_core_block_attach,
admin_core_block_detach,
admin_docs_get,
admin_docs_search_l0,
admin_docs_excerpts_get,
graph_query,
searches_create,
searches_get,
Expand Down Expand Up @@ -764,6 +767,9 @@ pub fn admin_router(state: AppState) -> Router {
"/v2/admin/core-blocks/attachments/{attachment_id}",
routing::delete(admin_core_block_detach),
)
.route("/v2/admin/docs/search/l0", routing::post(admin_docs_search_l0))
.route("/v2/admin/docs/excerpts", routing::post(admin_docs_excerpts_get))
.route("/v2/admin/docs/{doc_id}", routing::get(admin_docs_get))
.route("/v2/admin/notes", routing::get(notes_list))
.route("/v2/admin/notes/{note_id}", routing::get(notes_get))
.route(
Expand Down Expand Up @@ -1703,6 +1709,36 @@ async fn docs_get(
State(state): State<AppState>,
headers: HeaderMap,
Path(doc_id): Path<Uuid>,
) -> Result<Json<DocsGetResponse>, ApiError> {
docs_get_inner(state, headers, doc_id).await
}

#[utoipa::path(
get,
path = "/v2/admin/docs/{doc_id}",
tag = "admin",
params(("doc_id" = Uuid, Path, description = "Document ID.")),
responses(
(status = 200, description = "Document was fetched through the admin mirror.", body = Value),
(status = 400, description = "Invalid request.", body = ErrorBody),
(status = 401, description = "Authentication required.", body = ErrorBody),
(status = 403, description = "Admin access required.", body = ErrorBody),
(status = 404, description = "Document was not found.", body = ErrorBody),
(status = 500, description = "Internal error.", body = ErrorBody),
)
)]
async fn admin_docs_get(
State(state): State<AppState>,
headers: HeaderMap,
Path(doc_id): Path<Uuid>,
) -> Result<Json<DocsGetResponse>, ApiError> {
docs_get_inner(state, headers, doc_id).await
}

async fn docs_get_inner(
state: AppState,
headers: HeaderMap,
doc_id: Uuid,
) -> Result<Json<DocsGetResponse>, ApiError> {
let ctx = RequestContext::from_headers(&headers)?;
let read_profile = required_read_profile(&headers)?;
Expand Down Expand Up @@ -1738,6 +1774,36 @@ async fn docs_search_l0(
State(state): State<AppState>,
headers: HeaderMap,
payload: Result<Json<DocsSearchL0Body>, JsonRejection>,
) -> Result<Json<DocsSearchL0Response>, ApiError> {
docs_search_l0_inner(state, headers, payload).await
}

#[utoipa::path(
post,
path = "/v2/admin/docs/search/l0",
tag = "admin",
request_body = Value,
responses(
(status = 200, description = "L0 document search results through the admin mirror.", body = Value),
(status = 400, description = "Invalid request.", body = ErrorBody),
(status = 401, description = "Authentication required.", body = ErrorBody),
(status = 403, description = "Admin access required.", body = ErrorBody),
(status = 422, description = "Non-English input rejected.", body = ErrorBody),
(status = 500, description = "Internal error.", body = ErrorBody),
)
)]
async fn admin_docs_search_l0(
State(state): State<AppState>,
headers: HeaderMap,
payload: Result<Json<DocsSearchL0Body>, JsonRejection>,
) -> Result<Json<DocsSearchL0Response>, ApiError> {
docs_search_l0_inner(state, headers, payload).await
}

async fn docs_search_l0_inner(
state: AppState,
headers: HeaderMap,
payload: Result<Json<DocsSearchL0Body>, JsonRejection>,
) -> Result<Json<DocsSearchL0Response>, ApiError> {
let ctx = RequestContext::from_headers(&headers)?;
let read_profile = required_read_profile(&headers)?;
Expand Down Expand Up @@ -1846,6 +1912,36 @@ async fn docs_excerpts_get(
State(state): State<AppState>,
headers: HeaderMap,
payload: Result<Json<DocsExcerptsGetBody>, JsonRejection>,
) -> Result<Json<DocsExcerptResponse>, ApiError> {
docs_excerpts_get_inner(state, headers, payload).await
}

#[utoipa::path(
post,
path = "/v2/admin/docs/excerpts",
tag = "admin",
request_body = Value,
responses(
(status = 200, description = "Document excerpt result through the admin mirror.", body = Value),
(status = 400, description = "Invalid request.", body = ErrorBody),
(status = 401, description = "Authentication required.", body = ErrorBody),
(status = 403, description = "Admin access required.", body = ErrorBody),
(status = 404, description = "Document or excerpt was not found.", body = ErrorBody),
(status = 500, description = "Internal error.", body = ErrorBody),
)
)]
async fn admin_docs_excerpts_get(
State(state): State<AppState>,
headers: HeaderMap,
payload: Result<Json<DocsExcerptsGetBody>, JsonRejection>,
) -> Result<Json<DocsExcerptResponse>, ApiError> {
docs_excerpts_get_inner(state, headers, payload).await
}

async fn docs_excerpts_get_inner(
state: AppState,
headers: HeaderMap,
payload: Result<Json<DocsExcerptsGetBody>, JsonRejection>,
) -> Result<Json<DocsExcerptResponse>, ApiError> {
let ctx = RequestContext::from_headers(&headers)?;
let read_profile = required_read_profile(&headers)?;
Expand Down Expand Up @@ -4103,11 +4199,21 @@ mod tests {
}

#[test]
fn admin_viewer_is_admin_prefixed_and_read_only() {
fn admin_viewer_uses_admin_operator_routes_without_raw_memory_bypasses() {
let html = routes::VIEWER_HTML;

assert_eq!(ADMIN_VIEWER_PATH, "/viewer");
assert!(html.contains("/v2/admin/searches"));
assert!(html.contains("/v2/admin/docs/search/l0"));
assert!(html.contains("/v2/admin/docs/excerpts"));
assert!(html.contains("/v2/admin/docs/${encodeURIComponent(item.doc_id)}"));
assert!(html.contains("/v2/admin/dreaming/review-queue"));
assert!(html.contains(
"/v2/admin/consolidation/proposals/${encodeURIComponent(proposalId)}/review"
));
assert!(html.contains("/v2/admin/notes/${encodeURIComponent(noteId)}/history"));
assert!(html.contains("/v2/admin/notes/${encodeURIComponent(noteId)}/corrections"));
assert!(html.contains("/v2/admin/recall-debug/panel"));
assert!(html.contains("/v2/admin/traces/recent"));
assert!(html.contains("/v2/admin/traces/${encodeURIComponent(traceId)}/bundle"));
assert!(html.contains("/v2/admin/notes/"));
Expand All @@ -4120,6 +4226,12 @@ mod tests {
assert!(html.contains("Relation Context"));
assert!(html.contains("Knowledge Page Snippets"));
assert!(html.contains("Derived page: source documents"));
assert!(html.contains("Source Library"));
assert!(html.contains("Memory Inbox"));
assert!(html.contains("Memory History"));
assert!(html.contains("Recall Debug"));
assert!(html.contains("Apply Ledger Correction"));
assert!(html.contains("Apply / Supersede"));
assert!(html.contains("directTraceId"));
assert!(html.contains("trace_id"));
assert!(html.contains("loadInitialTrace"));
Expand Down
Loading