application capa

application-ai

Forge module wrapping infrastructure-ai.

Forge module wrapping infrastructure-ai.

Tierapplication
Roleunclassified (baselined)
Pathcrates/application/ai
Edition2024
Targetsapplication_ai, pg_ai_credentials
Public items25 across 4 modules
Tests17

What it is for

application-ai — wraps infrastructure-ai.

Sprint 3.55: before this sprint migrations() returned Vec::new() and migrate_pending returned Ok(0) while ignoring the pool, so ai_credentials (and its encryption functions + assert-encryption-key trigger, crates/infrastructure/ai/migrations/001_ai_credentials.sql) were never created by anything that actually called this module's own migration path — the same bug class application-research names and fixes for itself. This sprint also relocates application-classify's generic ai_credentials/ai_settings_admin admin surface here (Gate 1.5 OQ1, unanimous MOVE — nothing about it was classify-specific) and adds the RBAC gate neither crate had before (permission_codes below, crate::api::ai_settings_admin).

Deliberately narrow in scope: this crate owns migration application, credential admin, and provider construction/permissions for AI-provider access — it does not own report generation (domain-ai-report, explicitly deferred, see the sprint doc's OQ4) or prompt-template storage (application-prompts).

Capabilities

AiModule

application-ai — wraps infrastructure-ai.

Item
pub struct AiModule
AiModule :: fn new() -> Self
AiModule :: fn name(& self) -> & 'static str
AiModule :: fn version(& self) -> & 'static str
AiModule :: fn migrations(& self) -> Vec <MigrationSet>
AiModule :: async fn migrate_pending(& self, pool : & PgPool) -> std::result::Result <u32, MigrationError>
AiModule :: fn permission_codes(& self) -> Vec <String>

api (other)

HTTP API for application-ai.

Item
fn admin_router <S>() -> Router <S> where S : Clone + Send + Sync + 'static, PgPool : FromRef <S>,

api::ai_settings_admin (other)

AI settings admin REST endpoints (Sprint 45 — Gate 1.5 Q4).

Item
fn router <S>() -> Router <S> where S : Clone + Send + Sync + 'static, PgPool : FromRef <S>,

services::ai_credentials (other)

AI credentials service (Sprint 45).

Item
async fn resolve_key(pool : & PgPool, tenant_id : Uuid, provider : & str,) -> Result <Option <ResolvedKey>, AiCredentialsError>
async fn test_connection(pool : & PgPool, tenant_id : Uuid, provider : & str, provider_client : & dyn infrastructure_ai::AiProvider,) -> Result <TestConnectionResult, AiCredentialsError>

AiCredentialsError

AI credentials service (Sprint 45).

Item
pub enum AiCredentialsError
AiCredentialsError :: fn from(e : AiError) -> Self
async fn set_tenant_key(pool : & PgPool, tenant_id : Uuid, provider : & str, api_key : & str,) -> Result <(), AiCredentialsError>
async fn get_tenant_key(pool : & PgPool, tenant_id : Uuid, provider : & str,) -> Result <Option <String>, AiCredentialsError>
async fn delete_tenant_key(pool : & PgPool, tenant_id : Uuid, provider : & str,) -> Result <(), AiCredentialsError>
async fn has_tenant_key(pool : & PgPool, tenant_id : Uuid, provider : & str,) -> Result <bool, AiCredentialsError>
async fn list_tenant_providers(pool : & PgPool, tenant_id : Uuid,) -> Result <Vec <ProviderInfo>, AiCredentialsError>
async fn set_system_key(pool : & PgPool, provider : & str, api_key : & str,) -> Result <(), AiCredentialsError>
async fn get_system_key(pool : & PgPool, provider : & str,) -> Result <Option <String>, AiCredentialsError>
async fn delete_system_key(pool : & PgPool, provider : & str) -> Result <(), AiCredentialsError>
async fn has_system_key_for(pool : & PgPool, provider : & str) -> Result <bool, AiCredentialsError>
async fn list_system_providers(pool : & PgPool) -> Result <Vec <ProviderInfo>, AiCredentialsError>

ResolvedKey

AI credentials service (Sprint 45).

Item
pub struct ResolvedKey

TestConnectionResult

AI credentials service (Sprint 45).

Item
pub struct TestConnectionResult

How to use it

No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.

Module structure

application_ai

flowchart TD
  n_application_ai["application_ai"]
  n_application_ai --> n_api["api"]
  n_api --> n_api__ai_settings_admin["ai_settings_admin"]
  n_application_ai --> n_services["services"]
  n_services --> n_services__ai_credentials["ai_credentials"]

Public surface

`crate root`

ItemWhat it is
pub struct AiModule
AiModule :: fn new() -> Self
AiModule :: fn name(& self) -> & 'static str
AiModule :: fn version(& self) -> & 'static str
AiModule :: fn migrations(& self) -> Vec <MigrationSet>
AiModule :: async fn migrate_pending(& self, pool : & PgPool) -> std::result::Result <u32, MigrationError>
AiModule :: fn permission_codes(& self) -> Vec <String>

`api`

ItemWhat it is
fn admin_router <S>() -> Router <S> where S : Clone + Send + Sync + 'static, PgPool : FromRef <S>,The AI-settings admin router, generic over the consumer's state type S.

`api::ai_settings_admin`

ItemWhat it is
fn router <S>() -> Router <S> where S : Clone + Send + Sync + 'static, PgPool : FromRef <S>,

`services::ai_credentials`

ItemWhat it is
pub enum AiCredentialsError
AiCredentialsError :: fn from(e : AiError) -> Self
async fn set_tenant_key(pool : & PgPool, tenant_id : Uuid, provider : & str, api_key : & str,) -> Result <(), AiCredentialsError>
async fn get_tenant_key(pool : & PgPool, tenant_id : Uuid, provider : & str,) -> Result <Option <String>, AiCredentialsError>
async fn delete_tenant_key(pool : & PgPool, tenant_id : Uuid, provider : & str,) -> Result <(), AiCredentialsError>
async fn has_tenant_key(pool : & PgPool, tenant_id : Uuid, provider : & str,) -> Result <bool, AiCredentialsError>
async fn list_tenant_providers(pool : & PgPool, tenant_id : Uuid,) -> Result <Vec <ProviderInfo>, AiCredentialsError>
async fn set_system_key(pool : & PgPool, provider : & str, api_key : & str,) -> Result <(), AiCredentialsError>
async fn get_system_key(pool : & PgPool, provider : & str,) -> Result <Option <String>, AiCredentialsError>
async fn delete_system_key(pool : & PgPool, provider : & str) -> Result <(), AiCredentialsError>
async fn has_system_key_for(pool : & PgPool, provider : & str) -> Result <bool, AiCredentialsError>
async fn list_system_providers(pool : & PgPool) -> Result <Vec <ProviderInfo>, AiCredentialsError>
async fn resolve_key(pool : & PgPool, tenant_id : Uuid, provider : & str,) -> Result <Option <ResolvedKey>, AiCredentialsError>Resolve the effective API key for a (tenant, provider) pair — tenant-specific key takes precedence over system key
pub struct ResolvedKey
pub struct TestConnectionResult
async fn test_connection(pool : & PgPool, tenant_id : Uuid, provider : & str, provider_client : & dyn infrastructure_ai::AiProvider,) -> Result <TestConnectionResult, AiCredentialsError>Resolve the key, then call the provider with a tiny prompt (Sprint 47 — closes TD-CMS-AI-TEST-CONNECTION)

No pub use re-exports: every item above is declared in this crate.

Boundary

Reaches into infrastructure, platform.

Shares tier application with 120 other crates: application-agreements, application-analytics, application-approvals, application-assessments, application-audit-log, application-auth, application-billing, application-browser-automation, … (120 total).

_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._

Where it sits

Tier (ontology)application
Architectural role (taxonomy)unclassified (baselined)
Locationcrates/application/ai
Vocabulary in force (lexicon)current

Tier flow. Which tiers this crate's own edges cross.

flowchart LR
  n_application["application"] --> n_infrastructure["infrastructure"]
  n_application["application"] --> n_platform["platform"]

Dependencies

Runtime, in this workspace.

CrateTierOptionalOnly on
`application-core`applicationnoalways
`application-rbac`applicationnoalways
`infrastructure-ai`infrastructurenoalways
`platform-dto`platformnoalways

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
async-trait^0.1noalways
axum^0.7multipartnoalways
serde^1derivenoalways
serde_json^1noalways
sqlx^0.8runtime-tokio, postgres, chrono, uuid, jsonnoalways
thiserror^2noalways
uuid^1v4, v7, serde, jsnoalways

Development, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
tokio^1fullnoalways
tower^0.5noalways

Build. None.

Depended on by. 1 workspace crate.

Signal flow — what reaches this crate, and what it reaches.

flowchart LR
  n_application_classify["application-classify"] -->|uses| SELF
  SELF["application-ai"]
  SELF -->|runtime| n_application_core["application-core"]
  SELF -->|runtime| n_application_rbac["application-rbac"]
  SELF -->|runtime| n_infrastructure_ai["infrastructure-ai"]
  SELF -->|runtime| n_platform_dto["platform-dto"]
  classDef self fill:#1f883d,stroke:#1f883d,color:#fff;
  class SELF self;

Feature flags

No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.

Targets

KindNameSource
libapplication_ai`src/lib.rs`
testpg_ai_credentials`tests/pg_ai_credentials.rs`

Error model

Error typeNamed by
AiCredentialsErrordelete_system_key, delete_tenant_key, get_system_key, get_tenant_key, has_system_key_for, has_tenant_key, … (12 total)

Operational characteristics

PropertyEvidence
async public surfaceyes
async runtimenone detected
database accessyes
network I/Oyes
unsafe codenone detected
environment variablesyes

No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.

Configuration

VariableRead in
CARGO_PKG_VERSIONsrc/lib.rs

1 workspace crate depends on this one: application-classify.

Verification

KindCount
Unit tests13
Integration tests4
Examples0
Doctests0

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
crate root100
api101
api::ai_settings_admin101
services::ai_credentials1501

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc325
Public modules with a //! block34
pie showData
    title Public items with rustdoc
    "Documented" : 3
    "No rustdoc detected" : 22

Metrics

MetricValue
Rust source files5
Source lines778
Code lines574
Public API items25
Public modules4
Tests17
Examples0
Cargo features0
Direct runtime dependencies11
Workspace reverse dependencies1
pie showData
    title Public API by kind
    "enum" : 1
    "function" : 14
    "method" : 7
    "struct" : 3
pie showData
    title Rust source composition
    "Code" : 574
    "Blank or comment" : 204

Generation

Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.

Todas las application · Manual