blob: ea3f5891cdc8127455bca47ca36ed73b6f9d51fe [file]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
use super::{SendDelivery, SessionCreateInput, SessionSendInput};
use maka_agent_facts::{
durable::ExecutionIdentity,
room::{PublishedEvidence, RoomAuthor},
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
pub const ENDPOINT: &str = "agent";
pub const READ: &str = "readRootResource";
pub const LIST: &str = "listRootSessions";
pub const DELIVER: &str = "deliverRootOperation";
pub const MAX_HOPS: u8 = 6;
/// Metadata manifest for a binary attachment streamed alongside a cross-Root
/// Send or Wake call. Only this manifest (never raw bytes) is persisted in the
/// outbox and hashed into `request_digest`.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct CrossRootAttachment {
/// Attachment stream key in the Host transport `Attachments` map.
pub key: String,
/// Source Session artifact ID on the originating Root (used when streaming on dispatch).
pub source_artifact_id: String,
pub name: String,
pub mime_type: String,
pub bytes: u64,
pub digest: String,
}
#[derive(Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct DeliveryRequest {
pub request_digest: String,
pub operation: Operation,
}
#[derive(Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Operation {
pub op_id: uuid::Uuid,
pub source_root: String,
pub target_root: String,
pub hop_count: u8,
pub action: Action,
}
#[derive(Deserialize, Serialize, JsonSchema)]
#[serde(
tag = "kind",
rename_all = "snake_case",
rename_all_fields = "camelCase",
deny_unknown_fields
)]
pub enum Action {
Create {
input: Box<SessionCreateInput>,
},
Send {
input: Box<SessionSendInput>,
caller: Option<ExecutionIdentity>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
attachments: Vec<CrossRootAttachment>,
},
Wake {
source_room_id: String,
source_message_id: String,
target_session_id: String,
author: RoomAuthor,
message: String,
evidence: Vec<PublishedEvidence>,
#[serde(default, skip_serializing_if = "Option::is_none")]
context_envelope: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
delivery: Option<SendDelivery>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
attachments: Vec<CrossRootAttachment>,
},
Complete {
original_op_id: uuid::Uuid,
destination: CompletionDestination,
worker_session_id: String,
message_id: String,
status: CompletionStatus,
#[serde(default, skip_serializing_if = "Option::is_none")]
error: Option<String>,
},
}
#[derive(Clone, Deserialize, Serialize, JsonSchema)]
#[serde(
tag = "kind",
rename_all = "snake_case",
rename_all_fields = "camelCase",
deny_unknown_fields
)]
pub enum CompletionDestination {
Room {
session_id: String,
message_id: String,
},
Session {
session_id: String,
},
}
#[derive(Clone, Copy, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum CompletionStatus {
Completed,
Failed,
Cancelled,
}
#[derive(Deserialize, Serialize, JsonSchema)]
#[serde(
tag = "kind",
rename_all = "snake_case",
rename_all_fields = "camelCase",
deny_unknown_fields
)]
pub enum ReadOutput {
Page { value: serde_json::Value },
Image { mime_type: String, data: String },
}