Skip to main content

Crate sim_lib_openai_server

Crate sim_lib_openai_server 

Source
Expand description

OpenAI-compatible gateway skeleton for SIM.

This crate provides the OpenAI gateway health route, OpenAI JSON transcript codec, model discovery, gateway object helpers, and the first plan parsing and fixture atom execution surface through POST /v1/responses and POST /v1/chat/completions, embeddings through POST /v1/embeddings, audio, image, and vector-store fixtures, with SSE streaming projection, memory-backed response retrieval by id, and stored response replay/fork inspection routes. GET /v1/models advertises models from registered ModelCard records, so loadable local placement sites appear beside fixture and remote runner entries when installed.

Re-exports§

pub use capabilities::AI_RUNNER_CACHE_CAPABILITY;
pub use capabilities::NETWORK_CAPABILITY;
pub use capabilities::OPENAI_GATEWAY_ADMIN_CAPABILITY;
pub use capabilities::OPENAI_GATEWAY_FEDERATE_CAPABILITY;
pub use capabilities::OPENAI_GATEWAY_PLAN_CAPABILITY;
pub use capabilities::OPENAI_GATEWAY_PLAN_REMOTE_CAPABILITY;
pub use capabilities::OPENAI_GATEWAY_SERVE_CAPABILITY;
pub use capabilities::OPENAI_GATEWAY_TOOLS_CAPABILITY;
pub use capabilities::WEBHOOK_SERVE_CAPABILITY;
pub use capabilities::ai_runner_cache_capability;
pub use capabilities::network_capability;
pub use capabilities::openai_gateway_admin_capability;
pub use capabilities::openai_gateway_federate_capability;
pub use capabilities::openai_gateway_plan_capability;
pub use capabilities::openai_gateway_plan_remote_capability;
pub use capabilities::openai_gateway_serve_capabilities;
pub use capabilities::openai_gateway_serve_capability;
pub use capabilities::openai_gateway_tools_capability;
pub use capabilities::webhook_serve_capability;
pub use clock::DeterministicGatewayClock;
pub use clock::GatewayClock;
pub use clock::SystemGatewayClock;
pub use codec_openai::ChatTranscript;
pub use codec_openai::GatewayEventData;
pub use codec_openai::OpenAiCodec;
pub use codec_openai::OpenAiCodecOptions;
pub use codec_openai::OpenAiRequestOptions;
pub use codec_openai::OpenAiSseSurface;
pub use codec_openai::StreamSink;
pub use codec_openai::decode_openai_request;
pub use codec_openai::decode_openai_response;
pub use codec_openai::encode_gateway_events_sse;
pub use codec_openai::encode_openai_request;
pub use codec_openai::encode_openai_response;
pub use codec_openai::encode_openai_responses_response;
pub use codec_openai::gateway_event_data_from_packet;
pub use codec_openai::gateway_event_data_kind;
pub use codec_openai::gateway_event_data_packets;
pub use codec_openai::openai_codec_symbol;
pub use content_id::VOLATILE_REQUEST_FIELDS;
pub use content_id::content_id_for_expr;
pub use content_id::normalize_request_expr;
pub use content_id::request_content_id;
pub use content_id::request_expr_content_id;
pub use ids::GatewayIdGenerator;
pub use install::install_openai_gateway_lib;
pub use manifest::OpenAiGatewayLib;
pub use manifest::manifest_name;
pub use objects::GATEWAY_EVENT_OBJECT;
pub use objects::GATEWAY_REQUEST_OBJECT;
pub use objects::GATEWAY_RESPONSE_OBJECT;
pub use objects::GATEWAY_RUN_OBJECT;
pub use objects::GatewayEvent;
pub use objects::GatewayRequest;
pub use objects::GatewayResponse;
pub use objects::GatewayResponseValue;
pub use objects::GatewayRun;
pub use objects::content_id_expr;
pub use objects::content_id_hex;
pub use ops::OpenAiGatewayFunction;
pub use ops::cache_stats_symbol;
pub use ops::capability_report_symbol;
pub use ops::events_symbol;
pub use ops::fabric_symbol;
pub use ops::health_symbol;
pub use ops::key_add_symbol;
pub use ops::key_list_symbol;
pub use ops::model_health_symbol;
pub use ops::models_symbol;
pub use ops::plan_check_symbol;
pub use ops::plan_combinators_symbol;
pub use ops::plan_explain_symbol;
pub use ops::plan_parse_symbol;
pub use ops::plan_run_symbol;
pub use ops::run_get_symbol;
pub use ops::runs_symbol;
pub use ops::serve_symbol;
pub use ops::storage_stats_symbol;
pub use plan::BackendDescriptor;
pub use plan::PlanCombinator;
pub use plan::PlanEvalEvent;
pub use plan::PlanEvalReport;
pub use plan::PlanLimits;
pub use plan::check_plan;
pub use plan::check_plan_with_limits;
pub use plan::eval_plan;
pub use plan::eval_plan_report;
pub use plan::eval_plan_report_with_cache;
pub use plan::eval_plan_report_with_cache_and_runners;
pub use plan::eval_plan_report_with_cache_runners_and_federation;
pub use plan::eval_plan_report_with_federation;
pub use plan::explain_plan;
pub use plan::parse_plan;
pub use plan::plan_combinators;
pub use plan::plan_combinators_expr;
pub use plan::plan_symbol;
pub use plan::resolve_atom_address;
pub use routes::admin::ADMIN_CACHE_STATS_PATH;
pub use routes::admin::ADMIN_CAPABILITY_REPORT_PATH;
pub use routes::admin::ADMIN_EVENTS_PATH;
pub use routes::admin::ADMIN_MODEL_HEALTH_PATH;
pub use routes::admin::ADMIN_RUN_RETRIEVAL_PREFIX;
pub use routes::admin::ADMIN_RUN_RETRIEVAL_ROUTE;
pub use routes::admin::ADMIN_RUNS_PATH;
pub use routes::admin::ADMIN_STORAGE_STATS_PATH;
pub use routes::audio::AUDIO_SPEECH_PATH;
pub use routes::audio::AUDIO_TRANSCRIPTIONS_PATH;
pub use routes::audio::handle_audio_speech;
pub use routes::audio::handle_audio_transcriptions;
pub use routes::batches::BATCH_CANCEL_ROUTE;
pub use routes::batches::BATCH_RETRIEVAL_PREFIX;
pub use routes::batches::BATCH_RETRIEVAL_ROUTE;
pub use routes::batches::BATCHES_PATH;
pub use routes::batches::handle_batch_cancel;
pub use routes::batches::handle_batch_retrieval;
pub use routes::batches::handle_batches;
pub use routes::batches::retrieve_batch;
pub use routes::chat_completions::CHAT_COMPLETIONS_PATH;
pub use routes::chat_completions::ChatCompletionExecution;
pub use routes::chat_completions::execute_chat_completion_request;
pub use routes::chat_completions::execute_chat_completion_request_with_runners;
pub use routes::chat_completions::execute_chat_completion_request_with_runners_and_federation;
pub use routes::chat_completions::handle_chat_completions;
pub use routes::embeddings::EMBEDDINGS_PATH;
pub use routes::embeddings::EmbeddingExecution;
pub use routes::embeddings::EmbeddingIdGenerators;
pub use routes::embeddings::TENSOR_F64_SMALL_EMBEDDING_MODEL;
pub use routes::embeddings::execute_embedding_request;
pub use routes::embeddings::handle_embeddings;
pub use routes::files::FILE_RETRIEVAL_PREFIX;
pub use routes::files::FILE_RETRIEVAL_ROUTE;
pub use routes::files::FILES_PATH;
pub use routes::files::handle_file_retrieval;
pub use routes::files::handle_files;
pub use routes::files::retrieve_file;
pub use routes::health::HEALTH_BODY;
pub use routes::health::HEALTH_PATH;
pub use routes::health::health_response;
pub use routes::images::IMAGES_GENERATIONS_PATH;
pub use routes::images::handle_image_generations;
pub use routes::models::MODELS_PATH;
pub use routes::models::ModelCatalog;
pub use routes::models::OpenAiModel;
pub use routes::models::models_response;
pub use routes::models::models_response_for_catalog;
pub use routes::models::models_response_for_runner_args;
pub use routes::replay::RESPONSE_EVENTS_ROUTE;
pub use routes::replay::RESPONSE_EVENTS_SUFFIX;
pub use routes::replay::RESPONSE_SIM_ROUTE;
pub use routes::replay::RESPONSE_SIM_SUFFIX;
pub use routes::replay::SIM_EXTENSION_CAPABILITY;
pub use routes::replay::SIM_FORK_PATH;
pub use routes::replay::SIM_REPLAY_PATH;
pub use routes::replay::handle_response_events;
pub use routes::replay::handle_response_sim;
pub use routes::replay::handle_sim_fork;
pub use routes::replay::handle_sim_replay;
pub use routes::replay::response_events;
pub use routes::replay::response_sim;
pub use routes::responses::RESPONSE_RETRIEVAL_PREFIX;
pub use routes::responses::RESPONSE_RETRIEVAL_ROUTE;
pub use routes::responses::RESPONSES_PATH;
pub use routes::responses::ResponseExecution;
pub use routes::responses::ResponseIdGenerators;
pub use routes::responses::ResponseRuntimeTargets;
pub use routes::responses::execute_response_request;
pub use routes::responses::execute_response_request_with_cache;
pub use routes::responses::execute_response_request_with_cache_and_runners;
pub use routes::responses::execute_response_request_with_cache_runners_and_federation;
pub use routes::responses::execute_response_request_with_runners;
pub use routes::responses::handle_response_retrieval;
pub use routes::responses::handle_responses;
pub use routes::responses::retrieve_response;
pub use routes::threads::THREAD_MESSAGES_ROUTE;
pub use routes::threads::THREAD_RETRIEVAL_PREFIX;
pub use routes::threads::THREAD_RETRIEVAL_ROUTE;
pub use routes::threads::THREADS_PATH;
pub use routes::threads::handle_thread_get;
pub use routes::threads::handle_thread_post;
pub use routes::threads::handle_threads;
pub use routes::threads::list_messages;
pub use routes::threads::retrieve_thread;
pub use routes::vector_stores::VECTOR_STORE_SEARCH_PREFIX;
pub use routes::vector_stores::VECTOR_STORE_SEARCH_ROUTE;
pub use routes::vector_stores::VECTOR_STORE_SEARCH_SUFFIX;
pub use routes::vector_stores::VECTOR_STORES_PATH;
pub use routes::vector_stores::handle_vector_stores;
pub use runtime::OPENAI_GATEWAY_KEY_OBJECT;
pub use runtime::OpenAiFederatedGateway;
pub use runtime::OpenAiFederation;
pub use runtime::OpenAiFederationPolicy;
pub use runtime::OpenAiGatewayFabric;
pub use runtime::OpenAiGatewayKey;
pub use runtime::OpenAiKeyTable;
pub use runtime::OpenAiPlanCache;
pub use runtime::OpenAiRunnerRegistry;
pub use runtime::PlanCacheKey;
pub use runtime::PlanCacheMode;
pub use runtime::PlanCacheWriteTarget;
pub use runtime::ToolLoopConfig;
pub use runtime::global_openai_key_table;
pub use runtime::key_hash;
pub use runtime::redacted_gateway_request;
pub use runtime::run_tool_loop_with_cache;
pub use runtime::run_tool_loop_with_registry;
pub use server::GatewayRouteState;
pub use server::GatewayRoutes;
pub use server::GatewayRoutesValue;
pub use server::configure_routes;
pub use server::configure_routes_with_state;
pub use storage::GATEWAY_BATCH_KIND;
pub use storage::GATEWAY_FILE_KIND;
pub use storage::GATEWAY_THREAD_KIND;
pub use storage::GATEWAY_THREAD_MESSAGE_KIND;
pub use storage::GATEWAY_VECTOR_STORE_ITEM_KIND;
pub use storage::GATEWAY_VECTOR_STORE_KIND;
pub use storage::GatewayBatch;
pub use storage::GatewayBatchCounts;
pub use storage::GatewayBatchStatus;
pub use storage::GatewayFile;
pub use storage::GatewayFileStorageRef;
pub use storage::GatewayResponseObjectStore;
pub use storage::GatewayStateStore;
pub use storage::GatewayStore;
pub use storage::GatewayThread;
pub use storage::GatewayThreadMessage;
pub use storage::GatewayVectorStore;
pub use storage::GatewayVectorStoreItem;
pub use storage::MemoryGatewayStore;
pub use storage::StoredGatewayResponse;
pub use storage::TableGatewayStore;
pub use translate::tools::OpenAiTool;
pub use translate::tools::OpenAiToolCall;
pub use translate::tools::OpenAiToolRegistry;
pub use translate::tools::OpenAiToolResult;
pub use translate::tools::openai_name_to_symbol;
pub use translate::tools::symbol_from_text;

Modules§

capabilities
Capability identifiers and constructors that gate gateway operations.
citizen
Citizen descriptor types bridging gateway objects into the SIM object graph.
clock
Gateway clock abstractions for deterministic and system time sources.
codec_openai
OpenAI JSON codec surface: decode, encode, streaming, and shared shapes.
content_id
Content-id helpers that normalize and hash gateway request expressions.
ids
Identifier generation for gateway requests, responses, and runs.
install
Installation glue that registers the gateway library with a runtime.
manifest
Library manifest naming and export wiring for the gateway.
objects
Core gateway object records: requests, responses, runs, and events.
ops
Gateway operations exposed to the runtime as callable functions.
plan
Plan parsing, checking, evaluation, and combinator surface. Plan subsystem: parsing, checking, and evaluating SIM plan expressions that orchestrate model atoms through combinators such as race, fallback, chain, verify, debate, and cache.
routes
HTTP route handlers mapping OpenAI endpoints onto SIM eval and agents.
runtime
Runtime support: key tables, plan cache, federation, runners, and fabric.
server
Server wiring that registers gateway routes and holds route state.
storage
Persistent and in-memory stores for gateway records and content objects. Storage backends for the OpenAI-compatible gateway.
translate
Translation between OpenAI tool/function shapes and SIM symbols.