Skip to main content

Crate turul_ai_catalog_lambda

Crate turul_ai_catalog_lambda 

Source
Expand description

§turul-ai-catalog-lambda

An AWS Lambda handler that serves an AI Catalog at the well-known URI /.well-known/ai-catalog.json. The catalog is assembled from a turul-ai-catalog-storage store, validated, and served as canonical application/ai-catalog+json bytes.

Part of turul-agent-card.

  • GET and HEAD on the well-known path answer 200 with the catalog media type; other methods answer 405 with Allow: GET, HEAD; any other path answers 404.
  • Cold start fails if the catalog cannot be assembled or has an error diagnostic. A later refresh that fails keeps serving the last good snapshot.
  • The deployed function binary reads TURUL_AI_CATALOG_ID (required with dynamodb, otherwise default default), TURUL_AI_CATALOG_TABLE (with dynamodb) and TURUL_AI_CATALOG_MAX_AGE_SECS (default 60).

§Feature flags

FeatureEnables
dynamodbThe turul-ai-catalog-lambda binary reads the catalog from a DynamoDB table, and table_name is available.
localThe turul-ai-catalog-serve binary: the same handler on a plain HTTP port for local development.

Without dynamodb the function binary serves an empty in-memory store.

§Example

use lambda_http::{Body, http::Request};
use turul_ai_catalog_lambda::{ServedCatalog, handle};
use turul_ai_catalog_storage::{CatalogId, InMemoryCatalogStore};

let store = InMemoryCatalogStore::new();
let catalog = CatalogId::new("default")?;
let served = ServedCatalog::assemble(&store, &catalog, std::time::SystemTime::now()).await?;

let request = Request::builder()
    .uri("/.well-known/ai-catalog.json")
    .body(Body::Empty)?;
assert_eq!(handle(&served, &request).status(), 200);

§License

Apache-2.0.

Structs§

ServedCatalog
Canonical bytes of an assembled catalog that passed validate with no error diagnostic, with what that assembly left out.
SnapshotCache
The last good ServedCatalog, when it was last assembled or attempted, and the clock that decides when it is due. The clock lives here, never in handle.

Enums§

ColdStartError
Why the function cannot start or refresh its snapshot.

Constants§

ALLOW
Value of the Allow header on a 405 response (RFC 9110 section 15.5.6).
ID_VAR
Environment variable naming the catalog in the store.
MAX_AGE_VAR
Environment variable holding the snapshot refresh interval in seconds.
TABLE_VAR
Environment variable naming the DynamoDB table.

Functions§

catalog_id
Parses the catalog id from the value of ID_VAR; raw is None when the variable is unset.
handle
Answers a request for the well-known path, routing by path, then method. Pure: no I/O, clock or state.
max_age
Parses the snapshot refresh interval from the value of MAX_AGE_VAR: whole seconds, 60 when unset.
table_name
Parses the DynamoDB table name from the value of TABLE_VAR.