feat: complete Epic 1 production foundation

This commit is contained in:
bsodfather committed 2026-08-25 01:24:11 +03:00
1 parent 767428436d
commit 182bde8ac0
298 files changed
+35711 -5291

No files matched your search

+262 -6
View File
@@ -1,10 +1,12 @@
use crank_core::{
Agent, AgentId, AgentOperationBinding, AgentStatus, AgentVersion, ApprovalRequest,
ApprovalRequestId, ApprovalRequestStatus, AuthProfile, DescriptorId, ExportMode,
InvitationToken, InvocationLevel, InvocationLog, InvocationSource, MembershipRole, Operation,
OperationId, OperationSecurityLevel, OperationStatus, PlatformApiKey, PlatformApiKeyId,
Protocol, SampleId, Secret, SecretId, SecretVersion, ToolSelectionPolicy, UsagePeriod,
UsageRollup, User, UserSessionId, Workspace, WorkspaceId,
ApprovalRequestId, ApprovalRequestStatus, 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;
@@ -84,6 +86,56 @@ pub struct SessionRecord {
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)]
@@ -109,6 +161,60 @@ pub struct SecretRecord {
#[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)]
@@ -170,6 +276,114 @@ pub struct UsageAgentBreakdown {
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,
@@ -180,6 +394,7 @@ pub struct AgentSummary {
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>,
@@ -196,6 +411,15 @@ pub struct AgentVersionRecord {
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,
@@ -211,6 +435,7 @@ pub struct PublishedAgentTool {
#[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>,
}
@@ -229,6 +454,7 @@ pub struct OperationSummary {
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>,
@@ -485,11 +711,16 @@ impl InvocationHistoryWriteOutcome {
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,
}
@@ -507,6 +738,7 @@ pub struct UsageQuery<'a> {
pub period: UsagePeriod,
pub source: Option<InvocationSource>,
pub created_after: &'a str,
pub created_before: &'a str,
pub bucket: UsageBucket,
}
@@ -524,6 +756,13 @@ pub struct CreateVersionRequest<'a> {
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,
@@ -579,12 +818,22 @@ pub struct CreateAgentDraftVersionRequest<'a> {
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)]
@@ -594,6 +843,7 @@ pub struct SaveAgentCatalogConfigRequest<'a> {
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)]
@@ -603,6 +853,7 @@ pub struct PublishAgentRequest<'a> {
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)]
@@ -633,9 +884,12 @@ 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: &'a PlatformApiKeyId,
pub decided_by_key_id: Option<&'a PlatformApiKeyId>,
pub response_payload: Option<Value>,
pub decision_note: Option<&'a str>,
}
@@ -663,6 +917,7 @@ 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>,
}
@@ -672,6 +927,7 @@ pub struct RotateSecretRequest<'a> {
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>,