multiuser part 2
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::{
|
||||
Json,
|
||||
Json, Extension,
|
||||
extract::{Path, State},
|
||||
http::StatusCode,
|
||||
};
|
||||
@@ -9,7 +9,7 @@ use serde::Deserialize;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use skald_core::skald::Skald;
|
||||
use super::ApiError;
|
||||
use super::{ApiError, guard::AuthUser, require_context};
|
||||
|
||||
// ── Tool Permission Groups ────────────────────────────────────────────────────
|
||||
|
||||
@@ -87,12 +87,21 @@ pub struct SessionPath { pub session_id: i64 }
|
||||
/// POST body: the full RunContext object, or JSON `null` to clear the context.
|
||||
pub async fn set_session_run_context(
|
||||
State(skald): State<Arc<Skald>>,
|
||||
Extension(auth): Extension<AuthUser>,
|
||||
Path(p): Path<SessionPath>,
|
||||
Json(ctx): Json<Option<skald_core::run_context::RunContext>>,
|
||||
) -> Result<Json<Value>, ApiError> {
|
||||
skald.run_context_manager().set_session_run_context(p.session_id, ctx.as_ref()).await?;
|
||||
let uctx = require_context(&skald, &auth.user_id).await?;
|
||||
// The session row (and its live handler) live in the caller's own pool, so the
|
||||
// persist + live update both target the user's context. Run-context *definitions*
|
||||
// (roles) remain instance-wide; only the per-session value is owner data.
|
||||
skald_core::db::chat_sessions::set_run_context(
|
||||
&uctx.pool,
|
||||
p.session_id,
|
||||
ctx.as_ref().map(|c| c.to_db()).as_deref(),
|
||||
).await?;
|
||||
|
||||
if let Some(handler) = skald.manager().active_handler(p.session_id).await {
|
||||
if let Some(handler) = uctx.sessions.active_handler(p.session_id).await {
|
||||
handler.set_run_context(ctx).await;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user