260 lines
7.0 KiB
Rust
260 lines
7.0 KiB
Rust
use crank_core::{
|
|
Agent, AgentId, AgentOperationBinding, AgentStatus, AgentVersion, AuthProfile, DescriptorId,
|
|
ExportMode, Operation, OperationId, OperationStatus, Protocol, SampleId, Workspace,
|
|
WorkspaceId,
|
|
};
|
|
use crank_mapping::MappingSet;
|
|
use crank_schema::Schema;
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_json::Value;
|
|
|
|
macro_rules! define_registry_id {
|
|
($name:ident) => {
|
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
|
pub struct $name(String);
|
|
|
|
impl $name {
|
|
pub fn new(value: impl Into<String>) -> Self {
|
|
Self(value.into())
|
|
}
|
|
|
|
pub fn as_str(&self) -> &str {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
impl From<String> for $name {
|
|
fn from(value: String) -> Self {
|
|
Self(value)
|
|
}
|
|
}
|
|
|
|
impl From<&str> for $name {
|
|
fn from(value: &str) -> Self {
|
|
Self(value.to_owned())
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
define_registry_id!(YamlImportJobId);
|
|
|
|
pub type RegistryOperation = Operation<Schema, MappingSet>;
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct WorkspaceRecord {
|
|
pub workspace: Workspace,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct AgentSummary {
|
|
pub id: AgentId,
|
|
pub workspace_id: WorkspaceId,
|
|
pub slug: String,
|
|
pub display_name: String,
|
|
pub description: String,
|
|
pub status: AgentStatus,
|
|
pub current_draft_version: u32,
|
|
pub latest_published_version: Option<u32>,
|
|
pub created_at: String,
|
|
pub updated_at: String,
|
|
pub published_at: Option<String>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct AgentVersionRecord {
|
|
pub agent_id: AgentId,
|
|
pub workspace_id: WorkspaceId,
|
|
pub version: u32,
|
|
pub status: AgentStatus,
|
|
pub created_at: String,
|
|
pub snapshot: AgentVersion,
|
|
pub bindings: Vec<AgentOperationBinding>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct PublishedAgentTool {
|
|
pub workspace_id: WorkspaceId,
|
|
pub workspace_slug: String,
|
|
pub agent_id: AgentId,
|
|
pub agent_slug: String,
|
|
pub operation: RegistryOperation,
|
|
pub tool_name: String,
|
|
pub tool_title: String,
|
|
pub tool_description: String,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct OperationSummary {
|
|
pub id: OperationId,
|
|
pub workspace_id: WorkspaceId,
|
|
pub name: String,
|
|
pub display_name: String,
|
|
pub protocol: Protocol,
|
|
pub status: OperationStatus,
|
|
pub current_draft_version: u32,
|
|
pub latest_published_version: Option<u32>,
|
|
pub created_at: String,
|
|
pub updated_at: String,
|
|
pub published_at: Option<String>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct OperationVersionRecord {
|
|
pub operation_id: OperationId,
|
|
pub workspace_id: WorkspaceId,
|
|
pub version: u32,
|
|
pub status: OperationStatus,
|
|
pub change_note: Option<String>,
|
|
pub created_at: String,
|
|
pub created_by: Option<String>,
|
|
pub snapshot: RegistryOperation,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum SampleKind {
|
|
InputJson,
|
|
OutputJson,
|
|
YamlImportSource,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct OperationSampleMetadata {
|
|
pub id: SampleId,
|
|
pub operation_id: OperationId,
|
|
pub version: u32,
|
|
pub sample_kind: SampleKind,
|
|
pub storage_ref: String,
|
|
pub content_type: String,
|
|
pub file_name: Option<String>,
|
|
pub created_at: String,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum DescriptorKind {
|
|
ProtoUpload,
|
|
DescriptorSet,
|
|
ReflectionSnapshot,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct DescriptorMetadata {
|
|
pub id: DescriptorId,
|
|
pub operation_id: Option<OperationId>,
|
|
pub version: Option<u32>,
|
|
pub descriptor_kind: DescriptorKind,
|
|
pub storage_ref: String,
|
|
pub source_name: Option<String>,
|
|
pub package_index: Option<Value>,
|
|
pub created_at: String,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum YamlImportJobStatus {
|
|
Pending,
|
|
Completed,
|
|
Failed,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct YamlImportJob {
|
|
pub id: YamlImportJobId,
|
|
pub source_sample_id: Option<SampleId>,
|
|
pub status: YamlImportJobStatus,
|
|
pub format_version: String,
|
|
pub mode: ExportMode,
|
|
pub result_operation_id: Option<OperationId>,
|
|
pub result_version: Option<u32>,
|
|
pub error_text: Option<String>,
|
|
pub created_at: String,
|
|
pub finished_at: Option<String>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct YamlImportJobCompletion {
|
|
pub status: YamlImportJobStatus,
|
|
pub result_operation_id: Option<OperationId>,
|
|
pub result_version: Option<u32>,
|
|
pub error_text: Option<String>,
|
|
pub finished_at: String,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct CreateVersionRequest<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub snapshot: &'a RegistryOperation,
|
|
pub change_note: Option<&'a str>,
|
|
pub created_by: Option<&'a str>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct PublishRequest<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub operation_id: &'a OperationId,
|
|
pub version: u32,
|
|
pub published_at: &'a str,
|
|
pub published_by: Option<&'a str>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct CreateYamlImportJobRequest<'a> {
|
|
pub id: &'a YamlImportJobId,
|
|
pub source_sample_id: Option<&'a SampleId>,
|
|
pub format_version: &'a str,
|
|
pub mode: ExportMode,
|
|
pub created_at: &'a str,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct SaveAuthProfileRequest<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub profile: &'a AuthProfile,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct CreateWorkspaceRequest<'a> {
|
|
pub workspace: &'a Workspace,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct UpdateWorkspaceRequest<'a> {
|
|
pub workspace: &'a Workspace,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct CreateAgentRequest<'a> {
|
|
pub agent: &'a Agent,
|
|
pub version: &'a AgentVersion,
|
|
pub bindings: &'a [AgentOperationBinding],
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct SaveAgentBindingsRequest<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub agent_id: &'a AgentId,
|
|
pub agent_version: u32,
|
|
pub bindings: &'a [AgentOperationBinding],
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct PublishAgentRequest<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub agent_id: &'a AgentId,
|
|
pub version: u32,
|
|
pub published_at: &'a str,
|
|
pub published_by: Option<&'a str>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct SaveSampleMetadataRequest<'a> {
|
|
pub sample: &'a OperationSampleMetadata,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct SaveDescriptorMetadataRequest<'a> {
|
|
pub descriptor: &'a DescriptorMetadata,
|
|
}
|