AI Runtime APIs
AI-first map of chat sessions, model profiles, retrieval, MCP, and Blazor chat UI.
AI Runtime Discovery Map
AI runtime APIs create model-backed chat sessions, attach tools, add local retrieval, expose sessions through UI, and optionally publish the same tool surface through MCP.
User Intents
- Create an AI chat session for an app feature or script editor.
- Select or inspect the active model profile.
- Add docs search to a chat session.
- Register AI-callable tools.
- Render a reusable Blazor chat component.
- Host a reusable Codex thread/workspace/chat surface without making Codex lifecycle depend on Blazor.
- Add speech-to-text to chat input.
- Host tools through MCP for external clients.
- Build a coding-agent or Responses API based integration.
- Build, export, or copy the EyeAuras guidance pack for external coding agents.
Concept Model
AiEngineis the session factory and registry.IAiProfileRepositorystores templates and configuredAiModelProfileentries.AiChatSessionowns chat history, active profile, plugins, retrieval, artifact store, function-invocation policy, andAiConversationEngine.AiConversationEnginesends turns, streams updates, applies retrieval, tracks token usage, emits telemetry, and routes tool-call events to a sink.AiKernelPluginobjects expose tools and session instructions. Register them throughIAiSession.AddOrUpdatePlugin.IAiPluginHostowns the plugin catalog, lists tools, and can invoke tools by plugin/tool name.AiDocsKnowledgeBasePluginadds BM25-backed markdown documentation search and retrieval.AiChatViewModelimplementsIAiEventSinkand turns session events into timeline items.AiChatComponentrenders the chat transcript, tool calls, telemetry, artifacts, and input surface.AiMcpSessionandAiMcpServerHostexpose registered plugin tools as an MCP server.AiCodexManagerowns Codex runtime operations such as model listing, thread listing, thread reading/creation, archive, and live session resolution.AiCodexSessionis the Codex-backedAiCodingAgentSessionimplementation that still fits the normalAiChatSession/plugin/event-sink model.ICodexChatController/CodexChatControllerare UI-agnostic Codex shell controllers. They own start/stop, thread browser state, active thread lifecycle, model/reasoning selection, archive confirmation, and workspace attachments.CodexChatOptionsis the host adapter point for profile validation,CodexSessionOptions, session context, plugin registration, pre-send refresh, file/folder picking, and feature defaults. The session-options delegate is called again before active turns so hosts can refresh request-boundary readable/writable roots.CodexThreadListItemmaps rawAiCodexThreadSummaryvalues into presentation-independent thread picker rows.CodexWorkspaceAttachmentmaps selected files/directories into Codex workspace access rules. Directory attachments use the selected directory as writable root; file attachments keep the exact selected file path while using the parent directory as writable root.IEyeAurasAiGuidanceServicebuilds and exports the portable EyeAurasguidance-packfor external coding agents. Its public contract lives inEyeAuras.UI.Metadata; the desktop implementation lives inEyeAuras.UI.EyeAurasAiGuidanceContextdescribes the resolved docs repository snapshot and generated pack paths. Explicit-context methods reuse that snapshot, while no-context export/copy methods refresh the docs repository and rebuild the pack first.
Host / Runtime Contexts
- App/plugin code usually receives
AiEngine,IAiProfileRepository,IAiSpeechToTextService, factories, and configurators through dependency injection. - Razor components receive AI services through normal Blazor injection and own session/view-model lifetime.
- Top-level scripts or script projects should not assume AI services exist as global symbols. Use the host surface available in that script project.
- Ordinary helper classes must receive
IAiSession,AiEngine, plugins, or other AI dependencies explicitly. - AI runtime is not the same subsystem as CV/YOLO inference; only combine them when a feature needs both model-backed visual detection and chat/tool orchestration.
API Details
AiCoreServiceCollectionExtensions.AddAiCoreServices- registers core AI services: profile repository, transport events, API-key resolver, no-op speech service, Codex runtime host, andAiEngine.AiDesktopServiceCollectionExtensions.AddAiDesktopServices- adds desktop scripting AI, script editor window display, desktop speech-to-text, and script chat session configurators.AiEngine.CreateSession- creates a genericAiChatSession, applies the first configured profile when available, and registers the session with the engine.AiEngine.CreateMcpSession- createsAiMcpSessionfor tool hosting without chat transcript UI.AiEngine.AddCodexSession- creates a Codex-backed coding-agent session.AiEngine.RemoveSession,RemoveMcpSession,ClearSessions- dispose owned sessions and remove them from the engine registry.IAiChatSessionHandle- disposable ownership wrapper used by UI tabs or scoped workflows.AiSessionOptions.EnableArtifactStore- controls whether sessions register the built-inartifact_storeplugin.AiFunctionInvocationPolicy- allowlist, denylist, default approval mode, and approval callback for tool calls.AiToolCallFilter- Semantic Kernel invocation filter that enforces approval, publishes tool telemetry, and applies tool-call duration budgets.IAiTransportEvents- observes request/response transport data.IAiSpeechToTextService- UI-facing speech-to-text abstraction; core runtime registers a no-op implementation, desktop runtime registers the real service.IAiCodingAgentManager/AiCodexManager- Codex lifecycle and persisted thread operations.ICodexChatController- reusable, UI-agnostic Codex surface controller.PrepareActiveSessionForRequestAsyncruns the host pre-send callback and refreshes activeCodexSessionOptionsbefore the next turn.CodexChatOptions- host configuration delegate record for Codex controller startup, session creation, plugins, request preparation, and workspace picking.CodexThreadListItem.FromSummary- reusable mapper from raw Codex summaries to thread-browser display state.CodexWorkspaceAttachment.CreateValidated- validates and normalizes selected workspace files/folders.IEyeAurasAiGuidanceService.RefreshAsync- creates or refreshes the managed guidance pack from the configured docs repository, optional MCP status, and generation timestamp.IEyeAurasAiGuidanceService.ExportPackFolderAsync,ExportPackArchiveAsync,CopyPackToCsharpProjectAsync, andCopyPackToSolutionProjectAsync- export or copy the pack. Overloads withoutEyeAurasAiGuidanceContextassume the caller wants the latest docs and rebuild the pack before exporting or copying.
Profiles
IAiProfileRepository.Load/Savepersist model profile state.GetAllTemplates,GetBuiltInTemplates,GetCustomTemplatesdescribe available profile templates.GetConfiguredProfiles,FindConfiguredProfile,AddOrUpdateConfiguredProfile,RemoveConfiguredProfilemanage concrete profiles usable by sessions.AiModelProfilefields includeDisplayName,Provider,ModelId,Endpoint,ApiKeyRef,SupportsFunctionCalling,OrganizationId,ApiType,ReasoningEffort, andMaxContextTokens.- Supported provider anchors include
AiProvider.OpenAi,AiProvider.AzureOpenAi,AiProvider.Ollama, and OpenAI-compatible endpoint flows. AiApiType.ChatCompletionsuses Semantic Kernel chat completions wiring.AiApiType.Responsesis handled by the Responses adapter path.
Retrieval And Docs
AiDocsKnowledgeBasePluginexposesdoc_search,doc_get_chunk_preview,doc_get_chunk_full,doc_list_documents,doc_list_pinned_documents,doc_get_index_status, anddoc_reindex.IBm25KnowledgeBase.AddOrUpdateDocumentregisters a single markdown document.IBm25KnowledgeBase.AddOrUpdateDirectoryis an extension flow for adding a directory of markdown documents when available.Bm25Documentwraps anIFileInfo, timestamp, optional hash, description, kind, tags, source name, and pinned flag.- Pinned docs are treated as standing guidance by
AiDocsKnowledgeBasePlugin. IAiRetrievalServicecan inject local context into model requests before the turn is sent.AiKernelPlugin.GetRetrievalServiceslets a plugin contribute retrieval to a session.
UI
AiChatViewModelbinds anIAiChatSessionto chat UI state and implementsIAiEventSink.AiChatViewModel.SendAsync,CancelAsync,ClearAsync,RetryRequestAsyncare the main command handlers.AiChatViewModel.Session.SetEventSink(this)connects runtime events to UI.AiChatComponentrenders timeline items, request phases, tool calls, telemetry, reasoning, artifacts, and the input component.AiChatComponent.BeforeSendcan run app-specific logic before sending.AiChatComponent.InputFooterContentcan add host-specific controls.AiChatInputComponenthandles text input and speech-related UI.CodexChatComponentis a Codex-specific Blazor shell that composes loading state,CodexThreadBrowser, optionalCodexWorkspacePanel, and the existing genericAiChatComponent.CodexThreadBrowserrenders active/archived thread filtering, compact/all toggling, busy/status badges, and two-step archive confirmation fromICodexChatController.CodexWorkspacePanelrenders selected file/folder attachments and delegates add/remove actions back toICodexChatController.- Keep Codex-specific lifecycle in
ICodexChatController; keepAiChatComponentprovider-agnostic.
Common Flows
Generic Chat Session
- Load profiles through
IAiProfileRepository.Load. - Create a session with
AiEngine.CreateSession. - Optionally set or replace
ActiveProfileusingIAiChatSession.SetProfile. - Register plugins with
session.AddOrUpdatePlugin. - Create
AiChatViewModel(session, speechToTextService). - Render
AiChatComponentwith the view model as data context. - Dispose the view model and session handle together.
Script Editor Assistant
- Receive the active
IAuraScriptRunnerfrom the editor/tab context. - Create a session via
IScriptAiChatSessionFactory.CreateSession. - Let
IScriptAiChatSessionConfiguratorinstances attach workspace tools. - Build a docs plugin, add documentation files, and call
ReindexAsync. - Register docs with
session.AddOrUpdatePlugin. - Create
AiChatViewModel. - Store
AiChatViewModelandIAiChatSessionHandlein one disposable lifetime.
MCP Tool Host
- Create
AiMcpSessionthroughAiEngine.CreateMcpSession. - Register the same
AiKernelPlugininstances that would be used by a chat session. - Create
AiMcpServerHostwith listener options. - Start the host and give external MCP clients the endpoint URL.
- Stop and dispose the host/session when the feature is disabled.
Reusable Codex Chat Surface
- Create a
CodexChatControllerwithAiEngine,IAiCodingAgentManager, and host-specificCodexChatOptions. - Implement options delegates for profile/auth validation,
CodexSessionOptions, optionalIAiSessionContext, plugin registration, pre-send refresh, and optional file/folder picking. - Start the controller and render thread/workspace state through any view
technology. Blazor hosts can use
CodexChatComponent. - If using Blazor chat, adapt
ICodexChatController.ActiveSessionintoAiChatViewModel, seedCodexActiveThread.TranscriptItems, and pass the view model toCodexChatComponent. - Call
ICodexChatController.PrepareActiveSessionForRequestAsyncfromAiChatComponent.BeforeSend; the hostCreateSessionOptionsdelegate should include any current file or workspace root that Codex needs in the next sandbox policy. - Dispose view-specific chat adapters when
SessionRemovingfires, then dispose the controller.
Codex transcript rendering follows the app-server ThreadItem model. Live
agentMessage items render as AiChatItem assistant rows keyed by provider
item id and phase; the generic request response bubble is only used by
non-Codex chat backends that do not emit assistant transcript items directly.
Use AiChatItem.ProviderItemId, ProviderPhase, and CompletedTimestamp for
diagnostics or replay alignment, not for business logic.
External Agent Guidance Pack
- Resolve
IEyeAurasAiGuidanceServicefrom the app/plugin dependency container. - For UI status checks, call
ResolveExistingContextAsyncand inspect the returnedEyeAurasAiGuidanceContextpaths. - To rebuild the managed pack explicitly, call
RefreshAsync; passEyeAurasAiGuidanceRefreshOptions.Mcpwhen live MCP status should be embedded. - To hand the pack to an external agent without managing context yourself, call the no-context export/copy overload. Those methods refresh the docs repository and rebuild the pack first.
- Use the explicit-context overloads when a caller already refreshed the pack and wants to avoid a second docs update.
Assembly / Package Hints
- Core namespace:
EyeAuras.AI. - Plugin namespace:
EyeAuras.AI.SemanticKernel. - Retrieval namespace:
EyeAuras.AI.BM25. - UI namespace:
EyeAuras.AI.UI. - Codex runtime/controller namespace:
EyeAuras.AI.CodingAgents.Codex. - Codex Blazor shell namespace:
EyeAuras.AI.UI.Codex. - Desktop scripting namespace:
EyeAuras.AI.Desktop.Scripting. - MCP namespace:
EyeAuras.AI.Mcp. - Responses namespace:
EyeAuras.AI.ResponsesAPI. - Guidance-pack contract namespace:
EyeAuras.UI.AI.ServicesinEyeAuras.UI.Metadata. - AI runtime depends on Semantic Kernel and Model Context Protocol packages in app/module code. Do not assume these assemblies are referenced by every script project.
Prefer
- Prefer factory/configurator composition for feature-specific sessions.
- Prefer
IAiChatSessionHandleto make ownership explicit. - Prefer
AiDocsKnowledgeBasePluginfor local markdown docs instead of hand-built prompt stuffing. - Prefer
AiChatViewModel+AiChatComponentfor reusable Blazor chat UI. - Prefer
ICodexChatController+CodexChatOptionsfor reusable Codex lifecycle/thread/workspace surfaces. - Prefer
CodexThreadListItemandCodexWorkspaceAttachmentover duplicating app-specific thread/workspace DTOs. - Prefer
IEyeAurasAiGuidanceServicefor guidance-pack export/copy workflows instead of manually copying docs or editing a user's projectAGENTS.md. - Prefer
AiFunctionInvocationPolicyfor risky tools. - Prefer
IAiEventSinkevents for UI/telemetry instead of parsing logs.
Avoid
- Avoid creating sessions without loading profiles when the host expects persisted profile configuration.
- Avoid registering plugin tools with duplicate explicit names.
- Avoid assuming
SupportsFunctionCallingis true for every profile. - Avoid long-running tool methods without
CancellationTokensupport. - Avoid putting machine-local documentation paths in shared docs or prompts.
- Avoid mixing AI chat session lifetime into unrelated UI component lifetime.
- Avoid adding Codex-specific lifecycle or thread browser behavior to
AiChatComponent. - Avoid making Codex controller logic depend on Blazor types such as
RenderFragment, Razor components, or UI view models. - Avoid using explicit-context guidance-pack overloads when the caller has not already refreshed or validated the pack.
Research Anchors
AiEngineIAiSessionIAiChatSessionAiChatSessionAiConversationEngineIAiChatSessionHandleIAiSessionContextAiSessionOptionsIAiProfileRepositoryAiModelProfileAiKernelPluginIAiPluginHostAiDocsKnowledgeBasePluginIBm25KnowledgeBaseBm25DocumentAiChatViewModelAiChatComponentICodexChatControllerCodexChatControllerCodexChatOptionsCodexThreadListItemCodexWorkspaceAttachmentCodexChatComponentCodexThreadBrowserCodexWorkspacePanelIAiSpeechToTextServiceIScriptAiChatSessionFactoryIScriptAiChatSessionConfiguratorIEyeAurasAiGuidanceServiceEyeAurasAiGuidanceContextAiMcpSessionAiMcpServerHostResponsesConversationAdapterAiFunctionInvocationPolicyAiToolCallFilter
Search Synonyms
- AI runtime
- AI chat
- AI assistant
- chat session
- model profile
- profile repository
- tool calling
- function calling
- kernel plugin
- Semantic Kernel
- Responses API
- MCP server
- local docs
- docs search
- BM25
- retrieval augmented generation
- RAG
- artifact store
- speech to text
- coding agent
- Codex chat
- Codex thread browser
- Codex workspace attachment
- agent guidance
- guidance pack
- external coding agent
Related Maps
ml/ai.mdml/ai-kernel-plugins.mdscripting/runtime.mdwindows-subsystems/blazor-windows.mdrecipes/script-ai-editor-assistant.md