Capability first · transport second

AIProviderRuntime.js

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

SDK 0.5.18Runtime 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, automatic repeated-formatting-mark removal from cloned direct TTS payloads, 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 '/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: 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 mute controls.

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} = {})role, options = {}, {speechInputPrepared = false} = {}
AIProviderRuntime.chatpublic-memberchat(payload, options = {})payload, options = {}
AIProviderRuntime.streampublic-memberstream(payload, options = {})payload, 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)muted
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} = {})role, options = {}, {speechInputPrepared = false} = {}
AIProviderRuntime.chatmethodchat(payload, options = {})payload, options = {}
AIProviderRuntime.streammethodstream(payload, options = {})payload, options = {}
AIProviderRuntime.transcribemethodtranscribe(payload, options = {})payload, options = {}
AIProviderRuntime.synthesizemethodsynthesize(payload, options = {}, preparation = {})payload, options = {}, preparation = {}
AIProviderRuntime.cancelmethodcancel(role)role
AIProviderRuntime.setSpeechMutedasync methodasync setSpeechMuted(muted)muted

Parameter meanings and results

AIProviderRuntime is singleton-only. 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}. request(role,options={},preparation={}) and synthesize(payload,options={},preparation={}) automatically remove repeated same formatting marks from only a cloned direct-TTS payload input/text field. 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, automatic repeated-formatting-mark removal from cloned direct TTS payloads, 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 '/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.