MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / submit_proposal

Function submit_proposal

crates/openshell-supervisor-network/src/policy_local.rs:462–558  ·  view source on GitHub ↗
(ctx: &PolicyLocalContext, body: &[u8])

Source from the content-addressed store, hash-verified

460}
461
462async fn submit_proposal(ctx: &PolicyLocalContext, body: &[u8]) -> (u16, serde_json::Value) {
463 let Some(endpoint) = ctx.gateway_endpoint.as_deref() else {
464 return (
465 503,
466 serde_json::json!({
467 "error": "gateway_unavailable",
468 "detail": "policy proposal submission requires a gateway-connected sandbox"
469 }),
470 );
471 };
472 let Some(sandbox_name) = ctx
473 .sandbox_name
474 .as_deref()
475 .map(str::trim)
476 .filter(|name| !name.is_empty())
477 else {
478 return (
479 503,
480 serde_json::json!({
481 "error": "sandbox_name_unavailable",
482 "detail": "policy proposal submission requires a sandbox name"
483 }),
484 );
485 };
486
487 let chunks = match proposal_chunks_from_body(body) {
488 Ok(chunks) => chunks,
489 Err(error) => return (400, error_payload("invalid_proposal", error)),
490 };
491
492 let client = match openshell_core::grpc_client::CachedOpenShellClient::connect(endpoint).await {
493 Ok(client) => client,
494 Err(error) => {
495 return (
496 502,
497 serde_json::json!({
498 "error": "gateway_connect_failed",
499 "detail": error.to_string()
500 }),
501 );
502 }
503 };
504
505 // Pre-compute the audit summaries before handing `chunks` to the
506 // gateway client (which consumes the vec). The summaries pair up with
507 // the gateway's `accepted_chunk_ids` by index for the propose events
508 // emitted after submit returns.
509 let audit_summaries: Vec<String> = chunks.iter().map(summarize_chunk_for_audit).collect();
510
511 let response = match client
512 .submit_policy_analysis(sandbox_name, vec![], chunks, vec![], "agent_authored")
513 .await
514 {
515 Ok(response) => response,
516 Err(error) => {
517 return (
518 502,
519 serde_json::json!({

Callers 1

route_requestFunction · 0.85

Calls 8

error_payloadFunction · 0.85
connectFunction · 0.85
lenMethod · 0.80
is_emptyMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected