ctx-mgmt: ctx session management (dev mode only) (#2415)

This commit is contained in:
Lily Delalande
2025-05-02 16:12:56 -04:00
committed by GitHub
parent 2366a3ad01
commit 8ba40bdccc
19 changed files with 710 additions and 118 deletions
+43 -5
View File
@@ -11,20 +11,41 @@ use axum::{
use goose::message::Message;
use goose::session;
use goose::session::info::{get_session_info, SessionInfo, SortOrder};
use goose::session::SessionMetadata;
use serde::Serialize;
use utoipa::ToSchema;
#[derive(Serialize)]
struct SessionListResponse {
#[derive(Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct SessionListResponse {
/// List of available session information objects
sessions: Vec<SessionInfo>,
}
#[derive(Serialize)]
struct SessionHistoryResponse {
#[derive(Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct SessionHistoryResponse {
/// Unique identifier for the session
session_id: String,
metadata: session::SessionMetadata,
/// Session metadata containing creation time and other details
metadata: SessionMetadata,
/// List of messages in the session conversation
messages: Vec<Message>,
}
#[utoipa::path(
get,
path = "/sessions",
responses(
(status = 200, description = "List of available sessions retrieved successfully", body = SessionListResponse),
(status = 401, description = "Unauthorized - Invalid or missing API key"),
(status = 500, description = "Internal server error")
),
security(
("api_key" = [])
),
tag = "Session Management"
)]
// List all available sessions
async fn list_sessions(
State(state): State<Arc<AppState>>,
@@ -38,6 +59,23 @@ async fn list_sessions(
Ok(Json(SessionListResponse { sessions }))
}
#[utoipa::path(
get,
path = "/sessions/{session_id}",
params(
("session_id" = String, Path, description = "Unique identifier for the session")
),
responses(
(status = 200, description = "Session history retrieved successfully", body = SessionHistoryResponse),
(status = 401, description = "Unauthorized - Invalid or missing API key"),
(status = 404, description = "Session not found"),
(status = 500, description = "Internal server error")
),
security(
("api_key" = [])
),
tag = "Session Management"
)]
// Get a specific session's history
async fn get_session_history(
State(state): State<Arc<AppState>>,