Capability first · transport second

AIProviderRuntime.js

Provider-neutral selection, lifecycle, routing, startup, request, streaming, cancellation, and independent LLM/STT/TTS state.

SDK 0.97.1Runtime 0.8.12Protocol arcane/1
On this page

Overview

Provider-neutral selection, lifecycle, routing, startup, request, streaming, cancellation, and independent LLM/STT/TTS state.

  • Artifact
    AIProviderRuntime.js · esm
  • Classification
    public first party
  • Availability
    Cross-host in-process runtime; registered providers remain browser, native, or cloud specific
  • Normalization
    Normalizes mutable complete per-role routes, lifecycle/status, cancellation, streaming cleanup, capacity-1 FIFO LLM/STT lanes, bounded provider-declared parallel TTS requests with FIFO overflow, default repeated-formatting-mark removal from cloned direct TTS payloads or explicit textFormat:'plain' preservation with the control consumed before engine dispatch, local-only selection, direct LLM history/declaration/terminal structural contracts, complete all-choice content/reasoning FIFO iteration, private automatic provider draining with result-first buffering, terminal-only structural calls, exact per-choice observed/terminal correlation, and a separate complete validated terminal result without creating a fallback.

Import and lifecycle

JavaScript
import * as module from '/node_modules/arcane-os/runtime/arcane/modules/AIProviderRuntime.js';

The exported singleton owns registered providers and independent llm, stt, and tts lifecycle slots. Configuration, start, load, unload, request, cancellation, disposal, and mute operations publish complete mutable role state; importing alone performs no model download or provider selection. Requests enter a FIFO lane with capacity 1 for LLM/STT and provider-declared concurrent capacity for TTS; synthesis may settle out of order while AI playback preserves segment order. Each caller signal cancels only its own request.

Application-facing behavior: supportsTranscriptionCapture(providerId=null) reports the provider capture capability; createTranscriptionCapture(options) returns null or an owned start/stop/cancel/destroy/done handle with optional forceEndpoint. Start requires an idle ready selected STT role, remains in the initiating user gesture and is never queued. Capture holds that role until done joins cleanup; cancellation/retirement uses the same role owner. Native streaming TTS uses the existing request lane with ordered awaited PCM callbacks. Protocol constants; singleton-only AIProviderRuntime; aiProviderRuntime; getAIProviderRuntime(); provider registration/identity/selection, closed three-role and STT/TTS-only validation/configuration/replacement, status/catalog/inspection, startup, per-role load/unload/dispose/cancel, dispose-all, request/stream/speech aliases, SDK-internal speech-input preparation metadata, and setSpeechMuted(muted,{signal}={}) controls. Each pending unmute caller owns its abortable interest; the final interest aborts the owned activation while other preparation/playback or joining direct TTS-load interests preserve it. A pre-aborted unmute starts no activation. Explicit mute retains global cancellation and joined unload even with an aborted observer signal.

Protocol and host implementation

arcane-ai-runtime/2, arcane-ai-provider/2, arcane-ai-model-authority/1 This detail does not widen the application-facing API or grant authority.

Exports, signatures, parameters, and results

BindingFormDeclaration or signatureParameter syntax
AI_PROVIDER_PROTOCOLvariable · valuevariable AI_PROVIDER_PROTOCOL—
AI_PROVIDER_RUNTIME_PROTOCOLvariable · valuevariable AI_PROVIDER_RUNTIME_PROTOCOL—
AI_MODEL_AUTHORITY_PROTOCOLvariable · valuevariable AI_MODEL_AUTHORITY_PROTOCOL—
AIProviderRuntimeclassclass AIProviderRuntime—
aiProviderRuntimeclass · valuevariable aiProviderRuntime—
getAIProviderRuntimefunctionfunction getAIProviderRuntime()—
CallableKindExact public signatureParameter syntax
getAIProviderRuntimeexported-functionfunction getAIProviderRuntime()—
AIProviderRuntime.registerpublic-memberregister(provider)provider
AIProviderRuntime.unregisterpublic-memberunregister(role, providerId, expectedProvider = null)role, providerId, expectedProvider = null
AIProviderRuntime.hasProviderpublic-memberhasProvider(role, providerId)role, providerId
AIProviderRuntime.providerIdentitypublic-memberproviderIdentity(role, providerId)role, providerId
AIProviderRuntime.selectionpublic-memberselection(role, options = {})role, options = {}
AIProviderRuntime.ownsSelectionpublic-memberownsSelection(role, providerId, options = {})role, providerId, options = {}
AIProviderRuntime.validateConfigurationpublic-membervalidateConfiguration(value)value
AIProviderRuntime.configurepublic-memberconfigure(value)value
AIProviderRuntime.configureFromTuplepublic-memberconfigureFromTuple(tuple)tuple
AIProviderRuntime.statuspublic-memberstatus(role = null, options = {})role = null, options = {}
AIProviderRuntime.catalogpublic-membercatalog(role)role
AIProviderRuntime.inspectpublic-memberasync inspect(role, options = {})role, options = {}
AIProviderRuntime.startpublic-memberasync start(options)options
AIProviderRuntime.loadpublic-memberload(role, options = {})role, options = {}
AIProviderRuntime.unloadpublic-memberunload(role, options = {})role, options = {}
AIProviderRuntime.disposepublic-memberdispose(role, options = {})role, options = {}
AIProviderRuntime.disposeAllpublic-memberdisposeAll(options = {})options = {}
AIProviderRuntime.requestpublic-memberrequest(role, options = {}, {speechInputPrepared = false, observeToolText = null, onRetry = null, speechStream = null} = {})role, options = {}, {speechInputPrepared = false, observeToolText = null, onRetry = null, speechStream = null} = {}
AIProviderRuntime.chatpublic-memberchat(payload, options = {})payload, options = {}
AIProviderRuntime.streampublic-memberstream(payload, options = {})payload, options = {}
AIProviderRuntime.supportsTranscriptionCapturepublic-membersupportsTranscriptionCapture(providerId = null)providerId = null
AIProviderRuntime.createTranscriptionCapturepublic-membercreateTranscriptionCapture(options = {})options = {}
AIProviderRuntime.transcribepublic-membertranscribe(payload, options = {})payload, options = {}
AIProviderRuntime.synthesizepublic-membersynthesize(payload, options = {}, preparation = {})payload, options = {}, preparation = {}
AIProviderRuntime.cancelpublic-membercancel(role)role
AIProviderRuntime.setSpeechMutedpublic-memberasync setSpeechMuted(muted, {signal = null} = {})muted, {signal = null} = {}
MemberKindExact public declarationParameter syntax
AIProviderRuntime.constructorconstructorconstructor(authority)authority
AIProviderRuntime.protocolgetget protocol()—
AIProviderRuntime.speechMutedgetget speechMuted()—
AIProviderRuntime.configuredgetget configured()—
AIProviderRuntime.registermethodregister(provider)provider
AIProviderRuntime.unregistermethodunregister(role, providerId, expectedProvider = null)role, providerId, expectedProvider = null
AIProviderRuntime.hasProvidermethodhasProvider(role, providerId)role, providerId
AIProviderRuntime.ownsProvidermethodownsProvider(role, expectedProvider)role, expectedProvider
AIProviderRuntime.providerIdentitymethodproviderIdentity(role, providerId)role, providerId
AIProviderRuntime.selectionmethodselection(role, options = {})role, options = {}
AIProviderRuntime.ownsSelectionmethodownsSelection(role, providerId, options = {})role, providerId, options = {}
AIProviderRuntime.validateConfigurationmethodvalidateConfiguration(value)value
AIProviderRuntime.validateSpeechConfigurationmethodvalidateSpeechConfiguration(value)value
AIProviderRuntime.configuremethodconfigure(value)value
AIProviderRuntime.configureSpeechmethodconfigureSpeech(value)value
AIProviderRuntime.replaceSpeechProvidermethodreplaceSpeechProvider(role, value)role, value
AIProviderRuntime.replaceSpeechProvidersmethodreplaceSpeechProviders(value)value
AIProviderRuntime.configureFromTuplemethodconfigureFromTuple(tuple)tuple
AIProviderRuntime.statusmethodstatus(role = null, options = {})role = null, options = {}
AIProviderRuntime.catalogmethodcatalog(role)role
AIProviderRuntime.inspectasync methodasync inspect(role, options = {})role, options = {}
AIProviderRuntime.startasync methodasync start(options)options
AIProviderRuntime.loadmethodload(role, options = {})role, options = {}
AIProviderRuntime.unloadmethodunload(role, options = {})role, options = {}
AIProviderRuntime.disposemethoddispose(role, options = {})role, options = {}
AIProviderRuntime.disposeAllmethoddisposeAll(options = {})options = {}
AIProviderRuntime.requestmethodrequest(role, options = {}, {speechInputPrepared = false, observeToolText = null, onRetry = null, speechStream = null} = {})role, options = {}, {speechInputPrepared = false, observeToolText = null, onRetry = null, speechStream = null} = {}
AIProviderRuntime.chatmethodchat(payload, options = {})payload, options = {}
AIProviderRuntime.streammethodstream(payload, options = {})payload, options = {}
AIProviderRuntime.supportsTranscriptionCapturemethodsupportsTranscriptionCapture(providerId = null)providerId = null
AIProviderRuntime.createTranscriptionCapturemethodcreateTranscriptionCapture(options = {})options = {}
AIProviderRuntime.transcribemethodtranscribe(payload, options = {})payload, options = {}
AIProviderRuntime.synthesizemethodsynthesize(payload, options = {}, preparation = {})payload, options = {}, preparation = {}
AIProviderRuntime.cancelmethodcancel(role)role
AIProviderRuntime.setSpeechMutedasync methodasync setSpeechMuted(muted, {signal = null} = {})muted, {signal = null} = {}

Parameter meanings and results

AIProviderRuntime is singleton-only. supportsTranscriptionCapture(providerId=null) checks createCapture and its optional supportsCapture predicate. createTranscriptionCapture(options) returns null or a start/stop/cancel/destroy/done wrapper plus forceEndpoint when supplied. Start owns the initiating user gesture and requires an idle ready selected STT role; capture is never queued. The role remains owned until done joins actual cleanup. Slot cancellation and provider retirement cancel that capture through its retained request. Native streaming TTS uses the existing request lane, preserving ordered awaited PCM callbacks and native cleanup. Applications use AI.prepareTTSPlayback instead of its internal speechStream preparation seam. getAIProviderRuntime() returns aiProviderRuntime. status(role=null,options={}) returns the unchanged sticky lifecycle snapshot by default. Explicit options.execution=true copies that snapshot and adds the selected provider-supplied execution record when available; aggregate results place it under roles. It neither loads providers nor emits sticky-state events, and inspection errors propagate. Register a provider/2 object with required protocol, role, id, localOnly, catalog, inspect, status, load, request, unload, and dispose members; additional provider keys are accepted. Configuration is a closed {llm,stt,tts} record of {default,localOnly} routes. start({startMuted=true,startTranscription=false,signal=null}={}) waits for prior speech/unload work, declines a startup STT load unless explicitly requested, applies initial mute state, and returns the mutable startAIRuntime control {barrier,settled,cancel}. setSpeechMuted(muted,{signal}={}) gives each pending unmute caller its own abortable activation interest. The final pending interest aborts the owned activation, while other preparation/playback or joining direct TTS-load interests preserve it. A pre-aborted unmute starts no activation. Explicit mute retains global cancellation and joined unload even when its observer signal is aborted; actual provider cleanup remains provider-owned. request(role,options={},preparation={}) and synthesize(payload,options={},preparation={}) remove repeated same formatting marks from only a cloned direct-TTS payload input/text field by default. Explicit payload textFormat:'plain' preserves complete input/text, including repeated marks and surrounding whitespace; the SDK consumes textFormat before queued provider/engine dispatch. Omitted or other values retain default cleanup. This complete-call control does not change streaming behavior or upstream engine capacity. Their optional preparation argument is SDK-internal; {speechInputPrepared:true} prevents a second non-idempotent cleanup pass after an SDK owner has already prepared the outbound copy, and applications omit it. Caller payload and request objects remain unchanged. chat/stream/transcribe accept complete payloads plus {localOnly=false,signal=null}; per-role requests enter a FIFO lane without superseding or discarding earlier content; optional provider maxConcurrentRequests defaults to 1 and only TTS may declare a greater capacity. Direct LLM ingress validates tool declarations, exact all-ID pending-call history, and nonblank tool-result content. Structured terminals use exactly one message or choices envelope; ordinary iteration exposes complete nonstructural content/reasoning data from every choice in provider order, data callbacks retain complete chunks, and the separate result retains the complete validated terminal response.

Events, side effects, and errors

Source-literal CustomEvent dispatches

No source-literal CustomEvent dispatch is part of this artifact.

Lifecycle and event flow

  • publishes arcane-ai-runtime-state through AIRuntimeState
  • consumes arcane-ai-runtime-intent through AIRuntimeState

Direct coded failures

This artifact directly assigns no stable coded failure.

Exported Error subclasses

This artifact exports no Error subclass.

Documented failure behavior

  • ARCANE_AI_RUNTIME_SINGLETON_REQUIRED
  • ARCANE_AI_RUNTIME_NOT_CONFIGURED
  • ARCANE_AI_RUNTIME_CONFIGURING
  • ARCANE_AI_RUNTIME_DISPOSING
  • ARCANE_AI_RUNTIME_DISPOSED
  • ARCANE_AI_CONFIGURATION_REENTRANT
  • ARCANE_AI_OPERATION_SEQUENCE_EXHAUSTED
  • ARCANE_AI_PROVIDER_ALREADY_REGISTERED
  • ARCANE_AI_PROVIDER_RUNTIME_INVALID
  • ARCANE_AI_PROVIDER_LOCALITY_MISMATCH
  • ARCANE_AI_PROVIDER_SELECTED
  • ARCANE_AI_PROVIDER_AUTHORITY_BLOCKED
  • ARCANE_AI_PROVIDER_CALLBACK_BOUNDARY
  • ARCANE_AI_PROVIDER_STATUS_INVALID
  • ARCANE_AI_PROVIDER_STREAM_INVALID
  • ARCANE_AI_PROVIDER_UNAVAILABLE
  • ARCANE_AI_PROVIDER_NOT_READY
  • ARCANE_AI_PROVIDER_OPERATION_FAILED
  • ARCANE_AI_PROVIDER_UNLOAD_INCOMPLETE
  • ARCANE_AI_PROVIDER_DISPOSE_INCOMPLETE
  • ARCANE_AI_SELECTION_INCOMPLETE
  • ARCANE_AI_MODEL_AUTHORITY_REQUIRED
  • ARCANE_AI_LOCAL_PROVIDER_REQUIRED
  • AI_LOCAL_MODEL_REQUIRED
  • ARCANE_AI_ROLE_NOT_SELECTED
  • ARCANE_AI_ROLE_NOT_READY
  • ARCANE_AI_ROLE_BUSY
  • ARCANE_AI_ROLE_DISPOSED
  • ARCANE_AI_ROUTE_NOT_READY
  • ARCANE_AI_ROUTE_SWITCH_REQUIRES_UNLOAD
  • ARCANE_AI_OPERATION_SUPERSEDED
  • ARCANE_AI_REQUEST_ABORTED
  • ARCANE_AI_STREAM_CLEANUP_INCOMPLETE
  • ARCANE_AI_TTS_MUTED

Availability and capabilities

Cross-host in-process runtime; registered providers remain browser, native, or cloud specific. Normalizes mutable complete per-role routes, lifecycle/status, cancellation, streaming cleanup, capacity-1 FIFO LLM/STT lanes, bounded provider-declared parallel TTS requests with FIFO overflow, default repeated-formatting-mark removal from cloned direct TTS payloads or explicit textFormat:'plain' preservation with the control consumed before engine dispatch, local-only selection, direct LLM history/declaration/terminal structural contracts, complete all-choice content/reasoning FIFO iteration, private automatic provider draining with result-first buffering, terminal-only structural calls, exact per-choice observed/terminal correlation, and a separate complete validated terminal result without creating a fallback.

Provider-neutral in-process lifecycle. Browser, native, and cloud providers retain separate availability and authority; localOnly selects a matching route and never creates a fallback.

Contract example

JavaScript
import {getAIProviderRuntime} from '/node_modules/arcane-os/runtime/arcane/modules/AIProviderRuntime.js';

const runtime=getAIProviderRuntime();
console.log(runtime.protocol,runtime.status());

No direct Core call is claimed for this artifact. Any injected provider or consuming module retains its own documented authority.