999 lines
28 KiB
Rust
999 lines
28 KiB
Rust
use crank_artifacts::ArtifactRef;
|
|
use crank_core::{
|
|
Agent, AgentId, AgentOperationBinding, AgentStatus, AgentVersion, ApprovalRequest,
|
|
ApprovalRequestId, ApprovalRequestStatus, AuthKind, AuthProfile, DescriptorId,
|
|
ExecutionErrorCode, ExportMode, InvitationToken, InvocationLevel, InvocationLog,
|
|
InvocationLogId, InvocationSource, InvocationStatus, MembershipRole, OnboardingProjection,
|
|
Operation, OperationId, OperationSecurityLevel, OperationStatus, PlatformApiKey,
|
|
PlatformApiKeyId, ProductEvent, ProductEventId, ProductEventKind, Protocol, SampleId, Secret,
|
|
SecretId, SecretVersion, ToolSelectionPolicy, UsagePeriod, UsageRollup, User, UserId,
|
|
UserSessionId, Workspace, WorkspaceId,
|
|
};
|
|
use crank_mapping::MappingSet;
|
|
use crank_schema::Schema;
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_json::Value;
|
|
use time::OffsetDateTime;
|
|
|
|
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())
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
mod artifact_source;
|
|
|
|
pub use artifact_source::*;
|
|
|
|
define_registry_id!(YamlImportJobId);
|
|
define_registry_id!(ImportJobId);
|
|
define_registry_id!(WorkspaceUpstreamId);
|
|
|
|
pub type RegistryOperation = Operation<Schema, MappingSet>;
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct Page<T> {
|
|
pub items: Vec<T>,
|
|
pub total: u64,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct WorkspaceRecord {
|
|
pub workspace: Workspace,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct MembershipRecord {
|
|
pub workspace_id: WorkspaceId,
|
|
pub user: User,
|
|
pub role: MembershipRole,
|
|
pub created_at: OffsetDateTime,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct WorkspaceMembershipRecord {
|
|
pub workspace: Workspace,
|
|
pub role: MembershipRole,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct AuthUserRecord {
|
|
pub user: User,
|
|
pub password_hash: String,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct SessionRecord {
|
|
pub session_id: UserSessionId,
|
|
pub user: User,
|
|
pub memberships: Vec<WorkspaceMembershipRecord>,
|
|
pub current_workspace_id: Option<WorkspaceId>,
|
|
pub csrf_hash: Option<String>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct AdminBootstrapContractRecord {
|
|
pub id: String,
|
|
pub email: String,
|
|
pub display_name: String,
|
|
pub status: String,
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
pub expires_at: OffsetDateTime,
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
pub created_at: OffsetDateTime,
|
|
#[serde(with = "time::serde::rfc3339::option")]
|
|
pub used_at: Option<OffsetDateTime>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct CreateAdminBootstrapContractRequest<'a> {
|
|
pub id: &'a str,
|
|
pub token_hash: &'a str,
|
|
pub email: &'a str,
|
|
pub display_name: &'a str,
|
|
pub expires_at: &'a OffsetDateTime,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct ConsumeAdminBootstrapContractRequest<'a> {
|
|
pub token_hash: &'a str,
|
|
pub password_hash: &'a str,
|
|
pub now: &'a OffsetDateTime,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct AdminSecurityAuditRequest<'a> {
|
|
pub id: &'a str,
|
|
pub action: &'a str,
|
|
pub outcome: &'a str,
|
|
pub actor_user_id: Option<&'a UserId>,
|
|
pub session_id: Option<&'a UserSessionId>,
|
|
pub request_id: Option<&'a str>,
|
|
pub trace_id: Option<&'a str>,
|
|
pub source: &'a str,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct RecoverAdminPasswordRequest<'a> {
|
|
pub email: &'a str,
|
|
pub password_hash: &'a str,
|
|
pub audit_id: &'a str,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct InvitationRecord {
|
|
pub invitation: InvitationToken,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct PlatformApiKeyRecord {
|
|
pub api_key: PlatformApiKey,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct ApprovalRequestRecord {
|
|
pub approval: ApprovalRequest,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct SecretRecord {
|
|
pub secret: Secret,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct SecretVersionRecord {
|
|
pub secret_version: SecretVersion,
|
|
pub master_key_epoch: i64,
|
|
pub target_ciphertext: Option<String>,
|
|
pub target_key_version: Option<String>,
|
|
pub target_master_key_epoch: Option<i64>,
|
|
}
|
|
|
|
pub const MASTER_KEY_CIPHER_CONTRACT: &str = "secret-envelope-v2/aes-256-gcm-hkdf-sha256";
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct MasterKeyIdentityRecord {
|
|
pub epoch: i64,
|
|
pub fingerprint: String,
|
|
pub cipher_contract: String,
|
|
pub status: String,
|
|
pub backup_ref: Option<String>,
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
pub created_at: OffsetDateTime,
|
|
#[serde(with = "time::serde::rfc3339::option")]
|
|
pub activated_at: Option<OffsetDateTime>,
|
|
#[serde(with = "time::serde::rfc3339::option")]
|
|
pub retired_at: Option<OffsetDateTime>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct MasterKeyIdentityCandidate<'a> {
|
|
pub epoch: i64,
|
|
pub fingerprint: &'a str,
|
|
pub cipher_contract: &'a str,
|
|
pub observed_at: &'a OffsetDateTime,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct MasterKeyRotationRecord {
|
|
pub id: String,
|
|
pub source_epoch: i64,
|
|
pub target_epoch: i64,
|
|
pub target_fingerprint: String,
|
|
pub state: String,
|
|
pub backup_ref: Option<String>,
|
|
pub checkpoint_secret_id: Option<String>,
|
|
pub total_secret_versions: i64,
|
|
pub processed_secret_versions: i64,
|
|
pub verified_secret_versions: i64,
|
|
pub failure_code: Option<String>,
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
pub created_at: OffsetDateTime,
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
pub updated_at: OffsetDateTime,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct MasterKeyRotationStatus {
|
|
pub active_identity: Option<MasterKeyIdentityRecord>,
|
|
pub rotations: Vec<MasterKeyRotationRecord>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct WorkspaceUpstream {
|
|
pub id: WorkspaceUpstreamId,
|
|
pub workspace_id: WorkspaceId,
|
|
pub name: String,
|
|
pub base_url: String,
|
|
pub static_headers: Value,
|
|
pub auth_profile_id: Option<String>,
|
|
pub created_at: OffsetDateTime,
|
|
pub updated_at: OffsetDateTime,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct InvocationLogRecord {
|
|
pub log: InvocationLog,
|
|
pub operation_name: String,
|
|
pub operation_display_name: String,
|
|
pub agent_slug: Option<String>,
|
|
pub agent_display_name: Option<String>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct UsageRollupRecord {
|
|
pub rollup: UsageRollup,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct UsageTimelinePoint {
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
pub bucket_start: OffsetDateTime,
|
|
pub calls_ok: u64,
|
|
pub calls_error: u64,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct UsageOperationBreakdown {
|
|
pub operation_id: OperationId,
|
|
pub operation_name: String,
|
|
pub operation_display_name: String,
|
|
pub protocol: Protocol,
|
|
pub calls_total: u64,
|
|
pub calls_error: u64,
|
|
pub p50_ms: u64,
|
|
pub p95_ms: u64,
|
|
pub p99_ms: u64,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct UsageAgentBreakdown {
|
|
pub agent_id: AgentId,
|
|
pub agent_slug: String,
|
|
pub agent_display_name: String,
|
|
pub calls_total: u64,
|
|
pub calls_error: u64,
|
|
pub p50_ms: u64,
|
|
pub p95_ms: u64,
|
|
pub p99_ms: u64,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum UsageOutcomeGroup {
|
|
Success,
|
|
Upstream,
|
|
Client,
|
|
Schema,
|
|
Crank,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct UsageOutcomeBreakdown {
|
|
pub group: UsageOutcomeGroup,
|
|
pub execution_error_code: Option<ExecutionErrorCode>,
|
|
pub calls_total: u64,
|
|
pub p50_ms: u64,
|
|
pub p95_ms: u64,
|
|
pub p99_ms: u64,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum AppendProductEventOutcome {
|
|
Recorded,
|
|
Duplicate,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct ProductEventRecord {
|
|
pub event: ProductEvent,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct AppendProductEventRequest<'a> {
|
|
pub event: &'a ProductEvent,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct ListProductEventsQuery<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub kind: Option<ProductEventKind>,
|
|
pub created_after: OffsetDateTime,
|
|
pub created_before: OffsetDateTime,
|
|
pub limit: u32,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum OnboardingPresentationMilestone {
|
|
Eligible,
|
|
Started,
|
|
Resumed,
|
|
Dismissed,
|
|
Abandoned,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct RecordOnboardingMilestoneRequest<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub event_id: &'a ProductEventId,
|
|
pub milestone: OnboardingPresentationMilestone,
|
|
pub idempotency_key: &'a str,
|
|
pub expected_revision: i64,
|
|
pub occurred_at: OffsetDateTime,
|
|
pub eligible_since: Option<OffsetDateTime>,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct RecordOnboardingCompletionRequest<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub event_id: &'a ProductEventId,
|
|
pub idempotency_key: &'a str,
|
|
pub expected_revision: i64,
|
|
pub occurred_at: OffsetDateTime,
|
|
pub eligible_since: OffsetDateTime,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct OnboardingMilestoneResult {
|
|
pub accepted: bool,
|
|
pub projection: OnboardingProjection,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum InvocationRetentionStatus {
|
|
Noop,
|
|
Completed,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct InvocationRetentionPolicy {
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
pub requested_cutoff: OffsetDateTime,
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
pub effective_cutoff: OffsetDateTime,
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
pub usage_preservation_floor: OffsetDateTime,
|
|
pub preserved_usage_window_days: u16,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct InvocationRetentionOutcome {
|
|
pub status: InvocationRetentionStatus,
|
|
pub deleted_records: u64,
|
|
pub policy: InvocationRetentionPolicy,
|
|
}
|
|
|
|
#[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 catalog_revision: i64,
|
|
pub created_at: OffsetDateTime,
|
|
pub updated_at: OffsetDateTime,
|
|
pub published_at: Option<OffsetDateTime>,
|
|
}
|
|
|
|
#[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: OffsetDateTime,
|
|
pub snapshot: AgentVersion,
|
|
pub bindings: Vec<AgentOperationBinding>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct AgentStateExpectation {
|
|
pub status: AgentStatus,
|
|
pub current_draft_version: u32,
|
|
pub latest_published_version: Option<u32>,
|
|
pub catalog_revision: i64,
|
|
pub updated_at: OffsetDateTime,
|
|
}
|
|
|
|
#[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, Serialize, Deserialize)]
|
|
pub struct PublishedAgentCatalog {
|
|
pub agent_version: u32,
|
|
pub catalog_revision: String,
|
|
pub tool_selection_policy: ToolSelectionPolicy,
|
|
pub tools: Vec<PublishedAgentTool>,
|
|
}
|
|
|
|
#[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 category: String,
|
|
pub protocol: Protocol,
|
|
pub security_level: OperationSecurityLevel,
|
|
pub target_url: String,
|
|
pub target_action: String,
|
|
pub status: OperationStatus,
|
|
pub current_draft_version: u32,
|
|
pub latest_published_version: Option<u32>,
|
|
pub can_delete: bool,
|
|
pub created_at: OffsetDateTime,
|
|
pub updated_at: OffsetDateTime,
|
|
pub published_at: Option<OffsetDateTime>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct OperationUsageSummary {
|
|
pub operation_id: OperationId,
|
|
pub calls_today: u64,
|
|
pub error_rate_pct: f64,
|
|
pub avg_latency_ms: u64,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct OperationAgentRef {
|
|
pub operation_id: OperationId,
|
|
pub agent_id: AgentId,
|
|
pub agent_slug: String,
|
|
pub display_name: 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: OffsetDateTime,
|
|
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>,
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
pub created_at: OffsetDateTime,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum DescriptorKind {
|
|
ProtoUpload,
|
|
DescriptorSet,
|
|
ReflectionSnapshot,
|
|
WsdlUpload,
|
|
XsdUpload,
|
|
}
|
|
|
|
#[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>,
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
pub created_at: OffsetDateTime,
|
|
}
|
|
|
|
#[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>,
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
pub created_at: OffsetDateTime,
|
|
#[serde(with = "time::serde::rfc3339::option")]
|
|
pub finished_at: Option<OffsetDateTime>,
|
|
}
|
|
|
|
#[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>,
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
pub finished_at: OffsetDateTime,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum ImportJobStatus {
|
|
Pending,
|
|
Completed,
|
|
Failed,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum ImportJobKind {
|
|
OpenApi,
|
|
}
|
|
|
|
/// The bounded, opaque authority retained with an OpenAPI import job.
|
|
/// It is persisted inside the existing JSONB payload, never exposed by the
|
|
/// admin response, and is rechecked against workspace-scoped metadata at
|
|
/// apply time.
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct ImportJobSourceEnvelope {
|
|
pub source_id: ArtifactSourceId,
|
|
pub digest: ArtifactRef,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct ImportJob {
|
|
pub id: ImportJobId,
|
|
pub workspace_id: WorkspaceId,
|
|
pub kind: ImportJobKind,
|
|
pub source_format: String,
|
|
pub source_version: Option<String>,
|
|
pub status: ImportJobStatus,
|
|
pub preview_payload: Value,
|
|
pub created_operation_ids: Value,
|
|
pub error_text: Option<String>,
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
pub created_at: OffsetDateTime,
|
|
#[serde(with = "time::serde::rfc3339")]
|
|
pub expires_at: OffsetDateTime,
|
|
#[serde(with = "time::serde::rfc3339::option")]
|
|
pub finished_at: Option<OffsetDateTime>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct CreateImportJobRequest<'a> {
|
|
pub id: &'a ImportJobId,
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub kind: ImportJobKind,
|
|
pub source_format: &'a str,
|
|
pub source_version: Option<&'a str>,
|
|
pub status: ImportJobStatus,
|
|
pub source: &'a ImportJobSourceEnvelope,
|
|
pub preview_payload: &'a Value,
|
|
pub created_at: &'a OffsetDateTime,
|
|
pub expires_at: &'a OffsetDateTime,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct FinishImportJobRequest<'a> {
|
|
pub id: &'a ImportJobId,
|
|
pub status: ImportJobStatus,
|
|
pub created_operation_ids: &'a Value,
|
|
pub error_text: Option<&'a str>,
|
|
pub finished_at: &'a OffsetDateTime,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum ImportConflictMode {
|
|
Skip,
|
|
Rename,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct ImportOperationDraft {
|
|
pub operation_key: String,
|
|
pub operation: RegistryOperation,
|
|
/// The effective single-scheme requirement selected for this operation.
|
|
/// The registry checks it against the referenced profile inside Apply.
|
|
pub auth_requirement: Option<ImportAuthRequirement>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(tag = "kind", rename_all = "snake_case")]
|
|
pub enum ImportAuthRequirement {
|
|
Bearer,
|
|
Basic,
|
|
ApiKeyHeader { parameter_name: String },
|
|
ApiKeyQuery { parameter_name: String },
|
|
}
|
|
|
|
impl ImportAuthRequirement {
|
|
pub const fn kind(&self) -> AuthKind {
|
|
match self {
|
|
Self::Bearer => AuthKind::Bearer,
|
|
Self::Basic => AuthKind::Basic,
|
|
Self::ApiKeyHeader { .. } => AuthKind::ApiKeyHeader,
|
|
Self::ApiKeyQuery { .. } => AuthKind::ApiKeyQuery,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct AppliedImportOperation {
|
|
pub operation_key: String,
|
|
pub operation_id: OperationId,
|
|
pub name: String,
|
|
pub version: u32,
|
|
pub renamed_from: Option<String>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct SkippedImportOperation {
|
|
pub operation_key: String,
|
|
pub name: String,
|
|
pub reason: String,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct ImportJobApplyResult {
|
|
pub application_key: String,
|
|
pub created: Vec<AppliedImportOperation>,
|
|
pub skipped: Vec<SkippedImportOperation>,
|
|
}
|
|
|
|
/// Result of one bounded import-source maintenance pass.
|
|
///
|
|
/// The caller may schedule another pass when `more_work` is true. The report
|
|
/// intentionally contains only counts so it is safe to use in telemetry.
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
|
pub struct ImportJobCleanupReport {
|
|
pub deleted_jobs: u64,
|
|
pub detached_sources: u64,
|
|
pub more_work: bool,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct ApplyImportJobRequest<'a> {
|
|
pub id: &'a ImportJobId,
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub application_key: &'a str,
|
|
pub conflict_mode: ImportConflictMode,
|
|
pub operations: &'a [ImportOperationDraft],
|
|
/// Outcomes determined before the registry transaction (for example,
|
|
/// selected OpenAPI keys absent from the immutable preview). They are
|
|
/// persisted with the canonical result so retries remain equivalent.
|
|
pub pre_skipped: &'a [SkippedImportOperation],
|
|
pub finished_at: &'a OffsetDateTime,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct CreateInvocationLogRequest<'a> {
|
|
pub log: &'a InvocationLog,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub enum InvocationHistoryLossCategory {
|
|
Unavailable,
|
|
InvalidRecord,
|
|
}
|
|
|
|
impl InvocationHistoryLossCategory {
|
|
pub fn as_str(self) -> &'static str {
|
|
match self {
|
|
Self::Unavailable => "unavailable",
|
|
Self::InvalidRecord => "invalid_record",
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub struct InvocationHistoryLoss {
|
|
pub category: InvocationHistoryLossCategory,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub enum InvocationHistoryWriteOutcome {
|
|
Recorded,
|
|
Lost(InvocationHistoryLoss),
|
|
}
|
|
|
|
impl InvocationHistoryWriteOutcome {
|
|
pub fn loss(self) -> Option<InvocationHistoryLoss> {
|
|
match self {
|
|
Self::Recorded => None,
|
|
Self::Lost(loss) => Some(loss),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct ListInvocationLogsQuery<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub level: Option<InvocationLevel>,
|
|
pub status: Option<InvocationStatus>,
|
|
pub outcome_group: Option<UsageOutcomeGroup>,
|
|
pub search_text: Option<&'a str>,
|
|
pub source: Option<InvocationSource>,
|
|
pub operation_id: Option<&'a OperationId>,
|
|
pub agent_id: Option<&'a AgentId>,
|
|
pub created_after: Option<&'a str>,
|
|
pub created_before: Option<&'a str>,
|
|
pub cursor_created_at: Option<&'a str>,
|
|
pub cursor_id: Option<&'a InvocationLogId>,
|
|
pub limit: u32,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub enum UsageBucket {
|
|
Hour,
|
|
Day,
|
|
Week,
|
|
Month,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct UsageQuery<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub period: UsagePeriod,
|
|
pub source: Option<InvocationSource>,
|
|
pub created_after: &'a str,
|
|
pub created_before: &'a str,
|
|
pub bucket: UsageBucket,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct UsageSummary {
|
|
pub rollup: UsageRollup,
|
|
pub success_rate: f64,
|
|
}
|
|
|
|
#[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 OperationStateExpectation {
|
|
pub current_draft_version: u32,
|
|
pub status: OperationStatus,
|
|
pub latest_published_version: Option<u32>,
|
|
}
|
|
|
|
#[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 OffsetDateTime,
|
|
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 OffsetDateTime,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct SaveAuthProfileRequest<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub profile: &'a AuthProfile,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct SaveWorkspaceUpstreamRequest<'a> {
|
|
pub upstream: &'a WorkspaceUpstream,
|
|
}
|
|
|
|
#[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 CreateAgentDraftVersionRequest<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub agent_id: &'a AgentId,
|
|
pub version: &'a AgentVersion,
|
|
pub bindings: &'a [AgentOperationBinding],
|
|
pub updated_at: &'a OffsetDateTime,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct UpdateAgentSummaryRequest<'a> {
|
|
pub slug: &'a str,
|
|
pub display_name: &'a str,
|
|
pub description: &'a str,
|
|
pub updated_at: &'a OffsetDateTime,
|
|
pub expected_state: Option<&'a AgentStateExpectation>,
|
|
}
|
|
|
|
#[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],
|
|
pub expected_state: Option<&'a AgentStateExpectation>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct SaveAgentCatalogConfigRequest<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub agent_id: &'a AgentId,
|
|
pub agent_version: u32,
|
|
pub bindings: &'a [AgentOperationBinding],
|
|
pub tool_selection_policy: &'a ToolSelectionPolicy,
|
|
pub expected_state: Option<&'a AgentStateExpectation>,
|
|
}
|
|
|
|
#[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 OffsetDateTime,
|
|
pub published_by: Option<&'a str>,
|
|
pub expected_state: Option<&'a AgentStateExpectation>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct CreateInvitationRequest<'a> {
|
|
pub invitation: &'a InvitationToken,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct CreatePlatformApiKeyRequest<'a> {
|
|
pub api_key: &'a PlatformApiKey,
|
|
pub secret_hash: &'a str,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct CreateApprovalRequest<'a> {
|
|
pub approval: &'a ApprovalRequest,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct ListApprovalRequestsQuery<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub status: Option<ApprovalRequestStatus>,
|
|
pub limit: u32,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct DecideApprovalRequest<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub agent_id: &'a AgentId,
|
|
pub approval_id: &'a ApprovalRequestId,
|
|
pub operation_id: &'a OperationId,
|
|
pub operation_version: u32,
|
|
pub request_payload: &'a Value,
|
|
pub status: ApprovalRequestStatus,
|
|
pub decided_at: OffsetDateTime,
|
|
pub decided_by_key_id: Option<&'a PlatformApiKeyId>,
|
|
pub response_payload: Option<Value>,
|
|
pub decision_note: Option<&'a str>,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct FinishApprovalRequest<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub agent_id: &'a AgentId,
|
|
pub approval_id: &'a ApprovalRequestId,
|
|
pub status: ApprovalRequestStatus,
|
|
pub response_payload: Option<Value>,
|
|
pub decision_note: Option<&'a str>,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct ExpireApprovalRequest<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub agent_id: &'a AgentId,
|
|
pub approval_id: &'a ApprovalRequestId,
|
|
pub expired_at: OffsetDateTime,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct CreateSecretRequest<'a> {
|
|
pub secret: &'a Secret,
|
|
pub ciphertext: &'a str,
|
|
pub key_version: &'a str,
|
|
pub master_key_epoch: i64,
|
|
pub created_by: Option<&'a crank_core::UserId>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct RotateSecretRequest<'a> {
|
|
pub workspace_id: &'a WorkspaceId,
|
|
pub secret_id: &'a SecretId,
|
|
pub ciphertext: &'a str,
|
|
pub key_version: &'a str,
|
|
pub master_key_epoch: i64,
|
|
pub created_at: &'a OffsetDateTime,
|
|
pub updated_at: &'a OffsetDateTime,
|
|
pub created_by: Option<&'a crank_core::UserId>,
|
|
}
|
|
|
|
#[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,
|
|
}
|