On this page
Overview
Owns complete ordinary visible recurring AI turns, one active structural continuation, context construction, provider response preservation, and atomic history commit.
- Artifact
ConfiguredAIChatSession.js· esm - Classification
public first party - Availability
Native bridge by default; cross-host with injected chat - Normalization
Complete mutable session/result; declarations and emitted calls require nonempty user-facing arguments.message; ordered parallel calls and their exact IDs/names/arguments/extensions remain raw only through the active matching tool continuation, then settled recurrence becomes complete ordinary visible content; one atomic result batch must settle every pending ID; per-turn request options cannot replace session-owned messages or signal; persisted sequencing has stable coded failures; and provider rejection remains visible.
Import and lifecycle
import * as module from '/arcane/modules/ConfiguredAIChatSession.js';
Keeps complete recurring history only in memory. prepare makes one injected or default chat call and returns a mutable single-settlement commit/rollback transaction; send prepares and commits atomically only after a valid response. Raw structural tool protocol remains only through its one active continuation and is replaced with ordinary visible content when that continuation settles.
Application-facing behavior: default ConfiguredAIChatSession, named normalizeStructuralToolCall; constructor accepts complete initial messages and one unresolved ordered structural-call tail; history/clear/prepare/send; per-turn request overrides preserve session-owned messages/signal; every pending ID requires exactly one matching nonblank role=tool result in the same request batch; settled raw protocol does not recur.
Protocol and host implementation
Arcane.ai.chat or injected provider This detail does not widen the application-facing API or grant authority.
Exports, signatures, parameters, and results
| Binding | Form | Declaration or signature | Parameter syntax |
|---|---|---|---|
normalizeStructuralToolCall | function | function normalizeStructuralToolCall(call,label='Structural tool call') | call,label='Structural tool call' |
default | default · class | class ConfiguredAIChatSession | — |
| Callable | Kind | Exact public signature | Parameter syntax |
|---|---|---|---|
normalizeStructuralToolCall | exported-function | function normalizeStructuralToolCall(call,label='Structural tool call') | call,label='Structural tool call' |
ConfiguredAIChatSession.history | public-member | history() | — |
ConfiguredAIChatSession.clear | public-member | clear() | — |
ConfiguredAIChatSession.prepare | public-member | async prepare(input,options={}) | input,options={} |
ConfiguredAIChatSession.send | public-member | async send(input,options={}) | input,options={} |
| Member | Kind | Exact public declaration | Parameter syntax |
|---|---|---|---|
ConfiguredAIChatSession.constructor | constructor | constructor(options={}) | options={} |
ConfiguredAIChatSession.history | method | history() | — |
ConfiguredAIChatSession.clear | method | clear() | — |
ConfiguredAIChatSession.prepareOpening | async method | async prepareOpening(input,options={}) | input,options={} |
ConfiguredAIChatSession.prepare | async method | async prepare(input,options={}) | input,options={} |
ConfiguredAIChatSession.send | async method | async send(input,options={}) | input,options={} |
Parameter meanings and results
ConfiguredAIChatSession(options) accepts chat, contextBuilder, initialMessages, request, responseLength, and systemPrompt. responseLength is caller preference metadata and does not limit content. initialMessages accepts complete user/assistant/tool messages and one unresolved ordered structural function-call tail with unique IDs; a fully resulted tail without an active continuation and all other settled structural exchanges recur only as complete ordinary visible content. Every declared function tool must require parameters.properties.message as a string with minLength of at least one, and every returned function.arguments string must encode an object with a nonempty user-facing message. Exact call IDs, names, serialized arguments, and extension fields are preserved only in the returned response and active matching continuation. It exposes normalizeStructuralToolCall, history, clear, prepareOpening(input,{request?,signal?}), prepare(input,{request?,signal?}), and send(input,{request?,signal?}); constructor request defaults merge first, per-turn request options merge second, then the session owns signal and messages. prepareOpening makes one transient user bootstrap request and prepares only its complete nonblank assistant response for commit into an otherwise empty conversation. send accepts a user message, one matching tool result, or one atomic result batch containing exactly one nonblank role=tool message for every pending ID. A tool result may supply a complete public message, name, and status; all three fields are excluded from the raw provider continuation, only message becomes ordinary visible recurring content after settlement, and name/status remain optional durable transcript metadata. The optional contextBuilder receives mutable {input,history,signal}, and its complete result is included only in the current request. The injected chat(request) callback may return either the prior normalized provider result, preserving its explicit done boolean and complete providerResponse, or a non-stream OpenAI-compatible envelope whose first choice supplies the assistant message and normalizes to done:true. prepare and prepareOpening return mutable {response,commit,rollback}; send returns the mutable {provider,model,message:{role,content,tool_calls?},providerResponse,done,doneReason,promptEvalCount,evalCount} response after atomic commit.
Events, side effects, and errors
Source-literal CustomEvent dispatches
No source-literal CustomEvent dispatch is part of this artifact.
Lifecycle and event flow
This artifact has no additional documented lifecycle event flow.
Direct coded failures
This artifact directly assigns no stable coded failure.
Exported Error subclasses
This artifact exports no Error subclass.
Documented failure behavior
- AI_CHAT_UNAVAILABLE
- AI_CHAT_BUSY
- AI_CHAT_INVALID_RESPONSE
- AI_CHAT_INVALID_OPENING_RESPONSE
- AI_CHAT_OPENING_EXISTS
- AI_CHAT_ABORTED
- AI_CHAT_INVALID_TOOL_CALL
- AI_CHAT_INVALID_TOOL_MESSAGE
- AI_CHAT_TOOL_MESSAGE_REQUIRED
- AI_CHAT_TOOL_RESULT_REQUIRED
- AI_CHAT_TRANSACTION_SETTLED
- AI_CHAT_INCOHERENT_PERSISTENCE
- validation TypeError or RangeError
- provider rejection preserved
Availability and capabilities
Native bridge by default; cross-host with injected chat. Complete mutable session/result; declarations and emitted calls require nonempty user-facing arguments.message; ordered parallel calls and their exact IDs/names/arguments/extensions remain raw only through the active matching tool continuation, then settled recurrence becomes complete ordinary visible content; one atomic result batch must settle every pending ID; per-turn request options cannot replace session-owned messages or signal; persisted sequencing has stable coded failures; and provider rejection remains visible.
Defaults to Arcane.ai.chat but is cross-host with injected chat; it performs no provider selection, persistence, streaming, tools, or rendering.
Contract example
import ConfiguredAIChatSession from '/arcane/modules/ConfiguredAIChatSession.js';
const session=new ConfiguredAIChatSession({
systemPrompt:'Return the complete answer.',
chat:async request=>({
provider:'demo',
model:'echo',
message:{
role:'assistant',
content:'Received '+request.messages.length+' messages.'
}
})
});
console.log(await session.send('Hello'));